@@ -3,14 +3,14 @@ module ActiveRecord
3
3
module Reflection # :nodoc:
4
4
extend ActiveSupport ::Concern
5
5
6
- # Reflection allows you to interrogate Active Record classes and objects
6
+ # Reflection enables to interrogate Active Record classes and objects
7
7
# about their associations and aggregations. This information can,
8
- # for example, be used in a form builder that took an Active Record object
9
- # and created input fields for all of the attributes depending on their type
10
- # and displayed the associations to other objects.
8
+ # for example, be used in a form builder that takes an Active Record object
9
+ # and creates input fields for all of the attributes depending on their type
10
+ # and displays the associations to other objects.
11
11
#
12
- # You can find the interface for the AggregateReflection and AssociationReflection
13
- # classes in the abstract MacroReflection class .
12
+ # MacroReflection class has info for AggregateReflection and AssociationReflection
13
+ # classes.
14
14
module ClassMethods
15
15
def create_reflection ( macro , name , options , active_record )
16
16
case macro
@@ -24,7 +24,7 @@ def create_reflection(macro, name, options, active_record)
24
24
reflection
25
25
end
26
26
27
- # Returns a hash containing all AssociationReflection objects for the current class
27
+ # Returns a hash containing all AssociationReflection objects for the current class.
28
28
# Example:
29
29
#
30
30
# Invoice.reflections
@@ -39,9 +39,9 @@ def reflect_on_all_aggregations
39
39
reflections . values . select { |reflection | reflection . is_a? ( AggregateReflection ) }
40
40
end
41
41
42
- # Returns the AggregateReflection object for the named +aggregation+ (use the symbol). Example:
42
+ # Returns the AggregateReflection object for the named +aggregation+ (use the symbol).
43
43
#
44
- # Account.reflect_on_aggregation(:balance) # returns the balance AggregateReflection
44
+ # Account.reflect_on_aggregation(:balance) #=> the balance AggregateReflection
45
45
#
46
46
def reflect_on_aggregation ( aggregation )
47
47
reflections [ aggregation ] . is_a? ( AggregateReflection ) ? reflections [ aggregation ] : nil
@@ -78,8 +78,7 @@ def reflect_on_all_autosave_associations
78
78
end
79
79
80
80
81
- # Abstract base class for AggregateReflection and AssociationReflection that
82
- # describes the interface available for both of those classes. Objects of
81
+ # Abstract base class for AggregateReflection and AssociationReflection. Objects of
83
82
# AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
84
83
class MacroReflection
85
84
attr_reader :active_record
@@ -89,36 +88,41 @@ def initialize(macro, name, options, active_record)
89
88
end
90
89
91
90
# Returns the name of the macro.
92
- # <tt>composed_of :balance, :class_name => 'Money'</tt> will return <tt>:balance</tt>
93
- # <tt>has_many :clients</tt> will return <tt>:clients</tt>
91
+ #
92
+ # <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>:balance</tt>
93
+ # <tt>has_many :clients</tt> returns <tt>:clients</tt>
94
94
def name
95
95
@name
96
96
end
97
97
98
98
# Returns the macro type.
99
- # <tt>composed_of :balance, :class_name => 'Money'</tt> will return <tt>:composed_of</tt>
100
- # <tt>has_many :clients</tt> will return <tt>:has_many</tt>
99
+ #
100
+ # <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>:composed_of</tt>
101
+ # <tt>has_many :clients</tt> returns <tt>:has_many</tt>
101
102
def macro
102
103
@macro
103
104
end
104
105
105
106
# Returns the hash of options used for the macro.
106
- # <tt>composed_of :balance, :class_name => 'Money'</tt> will return <tt>{ :class_name => "Money" }</tt>
107
- # <tt>has_many :clients</tt> will return +{}+
107
+ #
108
+ # <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>{ :class_name => "Money" }</tt>
109
+ # <tt>has_many :clients</tt> returns +{}+
108
110
def options
109
111
@options
110
112
end
111
113
112
114
# Returns the class for the macro.
113
- # <tt>composed_of :balance, :class_name => 'Money'</tt> will return the Money class
114
- # <tt>has_many :clients</tt> will return the Client class
115
+ #
116
+ # <tt>composed_of :balance, :class_name => 'Money'</tt> returns the Money class
117
+ # <tt>has_many :clients</tt> returns the Client class
115
118
def klass
116
119
@klass ||= class_name . constantize
117
120
end
118
121
119
122
# Returns the class name for the macro.
120
- # <tt>composed_of :balance, :class_name => 'Money'</tt> will return <tt>'Money'</tt>
121
- # <tt>has_many :clients</tt> will return <tt>'Client'</tt>
123
+ #
124
+ # <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>'Money'</tt>
125
+ # <tt>has_many :clients</tt> returns <tt>'Client'</tt>
122
126
def class_name
123
127
@class_name ||= options [ :class_name ] || derive_class_name
124
128
end
@@ -153,7 +157,7 @@ class AggregateReflection < MacroReflection #:nodoc:
153
157
# Holds all the meta-data about an association as it was specified in the
154
158
# Active Record class.
155
159
class AssociationReflection < MacroReflection #:nodoc:
156
- # Returns the target association's class:
160
+ # Returns the target association's class.
157
161
#
158
162
# class Author < ActiveRecord::Base
159
163
# has_many :books
@@ -162,7 +166,7 @@ class AssociationReflection < MacroReflection #:nodoc:
162
166
# Author.reflect_on_association(:books).klass
163
167
# # => Book
164
168
#
165
- # <b>Note:</b> do not call +klass.new+ or +klass.create+ to instantiate
169
+ # <b>Note:</b> Do not call +klass.new+ or +klass.create+ to instantiate
166
170
# a new association object. Use +build_association+ or +create_association+
167
171
# instead. This allows plugins to hook into association object creation.
168
172
def klass
@@ -273,7 +277,7 @@ def polymorphic_inverse_of(associated_class)
273
277
end
274
278
275
279
# Returns whether or not this association reflection is for a collection
276
- # association. Returns +true+ if the +macro+ is one of +has_many+ or
280
+ # association. Returns +true+ if the +macro+ is either +has_many+ or
277
281
# +has_and_belongs_to_many+, +false+ otherwise.
278
282
def collection?
279
283
@collection
@@ -283,7 +287,7 @@ def collection?
283
287
# the parent's validation.
284
288
#
285
289
# Unless you explicitly disable validation with
286
- # <tt>:validate => false</tt>, it will take place when:
290
+ # <tt>:validate => false</tt>, validation will take place when:
287
291
#
288
292
# * you explicitly enable validation; <tt>:validate => true</tt>
289
293
# * you use autosave; <tt>:autosave => true</tt>
@@ -327,8 +331,6 @@ class ThroughReflection < AssociationReflection #:nodoc:
327
331
# Gets the source of the through reflection. It checks both a singularized
328
332
# and pluralized form for <tt>:belongs_to</tt> or <tt>:has_many</tt>.
329
333
#
330
- # (The <tt>:tags</tt> association on Tagging below.)
331
- #
332
334
# class Post < ActiveRecord::Base
333
335
# has_many :taggings
334
336
# has_many :tags, :through => :taggings
@@ -339,7 +341,7 @@ def source_reflection
339
341
end
340
342
341
343
# Returns the AssociationReflection object specified in the <tt>:through</tt> option
342
- # of a HasManyThrough or HasOneThrough association. Example:
344
+ # of a HasManyThrough or HasOneThrough association.
343
345
#
344
346
# class Post < ActiveRecord::Base
345
347
# has_many :taggings
0 commit comments