Skip to content
This repository
Browse code

Added MacroReflection#macro which will return a symbol describing the…

… macro used (like :composed_of or :has_many) #718, #248 [james@slashetc.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@805 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 85bb292a8fa95d9685b42b8a131d1f97aa34491c 1 parent ea26abe
David Heinemeier Hansson authored February 27, 2005
5  activerecord/CHANGELOG
... ...
@@ -1,3 +1,8 @@
  1
+*SVN*
  2
+
  3
+* Added MacroReflection#macro which will return a symbol describing the macro used (like :composed_of or :has_many) #718, #248 [james@slashetc.com]
  4
+
  5
+
1 6
 *1.7.0* (24th February, 2005)
2 7
 
3 8
 * Changed the auto-timestamping feature to use ActiveRecord::Base.default_timezone instead of entertaining the parallel ActiveRecord::Base.timestamps_gmt method. The latter is now deprecated and will throw a warning on use (but still work) #710 [Jamis Buck]
14  activerecord/lib/active_record/reflection.rb
@@ -10,7 +10,7 @@ class << self
10 10
 
11 11
           def composed_of_with_reflection(part_id, options = {})
12 12
             composed_of_without_reflection(part_id, options)
13  
-            write_inheritable_array "aggregations", [ AggregateReflection.new(part_id, options, self) ]
  13
+            write_inheritable_array "aggregations", [ AggregateReflection.new(:composed_of, part_id, options, self) ]
14 14
           end
15 15
 
16 16
           alias_method :composed_of, :composed_of_with_reflection          
@@ -24,7 +24,7 @@ class << self
24 24
 
25 25
             def #{association_type}_with_reflection(association_id, options = {})
26 26
               #{association_type}_without_reflection(association_id, options)
27  
-              write_inheritable_array "associations", [ AssociationReflection.new(association_id, options, self) ]
  27
+              write_inheritable_array "associations", [ AssociationReflection.new(:#{association_type}, association_id, options, self) ]
28 28
             end
29 29
 
30 30
             alias_method :#{association_type}, :#{association_type}_with_reflection          
@@ -67,8 +67,8 @@ def reflect_on_association(association)
67 67
     # those classes. Objects of AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
68 68
     class MacroReflection
69 69
       attr_reader :active_record
70  
-      def initialize(name, options, active_record)
71  
-        @name, @options, @active_record = name, options, active_record
  70
+      def initialize(macro, name, options, active_record)
  71
+        @macro, @name, @options, @active_record = macro, name, options, active_record
72 72
       end
73 73
       
74 74
       # Returns the name of the macro, so it would return :balance for "composed_of :balance, :class_name => 'Money'" or
@@ -77,6 +77,12 @@ def name
77 77
         @name
78 78
       end
79 79
       
  80
+      # Returns the name of the macro, so it would return :composed_of for 
  81
+      # "composed_of :balance, :class_name => 'Money'" or :has_many for "has_many :clients".
  82
+      def macro
  83
+        @macro
  84
+      end
  85
+      
80 86
       # Returns the hash of options used for the macro, so it would return { :class_name => "Money" } for 
81 87
       # "composed_of :balance, :class_name => 'Money'" or {} for "has_many :clients".
82 88
       def options
6  activerecord/test/reflection_test.rb
@@ -42,11 +42,11 @@ def test_integer_columns
42 42
 
43 43
   def test_aggregation_reflection
44 44
     reflection_for_address = ActiveRecord::Reflection::AggregateReflection.new(
45  
-      :address, { :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ] }, Customer
  45
+      :composed_of, :address, { :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ] }, Customer
46 46
     )
47 47
 
48 48
     reflection_for_balance = ActiveRecord::Reflection::AggregateReflection.new(
49  
-      :balance, { :class_name => "Money", :mapping => %w(balance amount) }, Customer
  49
+      :composed_of, :balance, { :class_name => "Money", :mapping => %w(balance amount) }, Customer
50 50
     )
51 51
 
52 52
     assert_equal(
@@ -61,7 +61,7 @@ def test_aggregation_reflection
61 61
   
62 62
   def test_association_reflection
63 63
     reflection_for_clients = ActiveRecord::Reflection::AssociationReflection.new(
64  
-      :clients, { :order => "id", :dependent => true }, Firm
  64
+      :has_many, :clients, { :order => "id", :dependent => true }, Firm
65 65
     )
66 66
 
67 67
     assert_equal reflection_for_clients, Firm.reflect_on_association(:clients)

0 notes on commit 85bb292

Please sign in to comment.
Something went wrong with that request. Please try again.