Ticket #8884: doc_ar_reflection.2.diff
| File doc_ar_reflection.2.diff, 2.7 kB (added by jeremymcanally, 10 months ago) |
|---|
-
activerecord/lib/active_record/reflection.rb
old new 76 76 @macro, @name, @options, @active_record = macro, name, options, active_record 77 77 end 78 78 79 # Returns the name of the macro , so it would return :balance for "composed_of :balance, :class_name => 'Money'" or80 # :clients for "has_many :clients".79 # Returns the name of the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return 80 # +:balance+ or for <tt>has_many :clients</tt> it will return +:clients+. 81 81 def name 82 82 @name 83 83 end 84 84 85 # Returns the name of the macro, so it would return :composed_of for86 # "composed_of :balance, :class_name => 'Money'" or :has_many for "has_many :clients".85 # Returns the macro type. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> will return +:composed_of+ 86 # or for <tt>has_many :clients</tt> will return +:has_many+. 87 87 def macro 88 88 @macro 89 89 end 90 90 91 # Returns the hash of options used for the macro , so it would return { :class_name => "Money" }for92 # "composed_of :balance, :class_name => 'Money'" or {} for "has_many :clients".91 # Returns the hash of options used for the macro. For example, it would return <tt>{ :class_name => "Money" }</tt> for 92 # <tt>composed_of :balance, :class_name => 'Money'</tt> or +{}+ for <tt>has_many :clients</tt>. 93 93 def options 94 94 @options 95 95 end 96 96 97 # Returns the class for the macro , so "composed_of :balance, :class_name => 'Money'" returns the Money class and98 # "has_many :clients" returns the Clientclass.97 # Returns the class for the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns the +Money+ 98 # class and <tt>has_many :clients</tt> returns the +Client+ class. 99 99 def klass 100 100 @klass ||= class_name.constantize 101 101 end 102 102 103 # Returns the class name for the macro. For example, <tt>composed_of :balance, :class_name => 'Money'</tt> returns +Money+ 104 # and <tt>has_many :clients</tt> returns +Client+. 103 105 def class_name 104 106 @class_name ||= options[:class_name] || derive_class_name 105 107 end 106 108 109 # Returns +true+ if +self+ and +other_aggregation+ have the same +name+ attribute, +active_record+ attribute, 110 # and +other_aggregation+ has an options hash assigned to it. 107 111 def ==(other_aggregation) 108 112 name == other_aggregation.name && other_aggregation.options && active_record == other_aggregation.active_record 109 113 end