Skip to content
This repository
Browse code

Sync with rails/rails/master, merge two metaprogramming annotation ef…

…forts
  • Loading branch information...
commit 2b8750eba439c4b829b2e8172a1edc0dfa9c532b 2 parents e523b43 + 0efec64
Michael Klishin authored December 28, 2008

Showing 34 changed files with 437 additions and 285 deletions. Show diff stats Hide diff stats

  1. 6  actionpack/lib/action_controller/helpers.rb
  2. 6  actionpack/lib/action_controller/mime_responds.rb
  3. 18  actionpack/lib/action_controller/polymorphic_routes.rb
  4. 2  actionpack/lib/action_controller/request.rb
  5. 61  actionpack/lib/action_controller/routing/route_set.rb
  6. 6  actionpack/lib/action_controller/test_process.rb
  7. 10  actionpack/lib/action_view/helpers/form_helper.rb
  8. 4  actionpack/test/controller/rack_test.rb
  9. 2  activerecord/CHANGELOG
  10. 1  activerecord/lib/active_record.rb
  11. 36  activerecord/lib/active_record/associations.rb
  12. 73  activerecord/lib/active_record/base.rb
  13. 12  activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
  14. 48  activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  15. 24  activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  16. 14  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  17. 2  activerecord/lib/active_record/dirty.rb
  18. 25  activerecord/lib/active_record/dynamic_scope_match.rb
  19. 20  activerecord/test/cases/named_scope_test.rb
  20. 8  activeresource/lib/active_resource/http_mock.rb
  21. 32  activesupport/lib/active_support/callbacks.rb
  22. 48  activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
  23. 33  activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
  24. 54  activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
  25. 12  activesupport/lib/active_support/core_ext/logger.rb
  26. 6  activesupport/lib/active_support/core_ext/module/aliasing.rb
  27. 8  activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
  28. 48  activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
  29. 6  activesupport/lib/active_support/core_ext/module/delegation.rb
  30. 10  activesupport/lib/active_support/core_ext/module/synchronization.rb
  31. 15  activesupport/lib/active_support/deprecation.rb
  32. 58  activesupport/lib/active_support/memoizable.rb
  33. 12  railties/lib/rails_generator/generators/applications/app/template_runner.rb
  34. 2  railties/test/generators/rails_template_runner_test.rb
6  actionpack/lib/action_controller/helpers.rb
@@ -163,9 +163,9 @@ def helper(*args, &block)
163 163
       def helper_method(*methods)
164 164
         methods.flatten.each do |method|
165 165
           master_helper_module.module_eval <<-end_eval
166  
-            def #{method}(*args, &block)
167  
-              controller.send(%(#{method}), *args, &block)
168  
-            end
  166
+            def #{method}(*args, &block)                    # def current_user(*args, &block)
  167
+              controller.send(%(#{method}), *args, &block)  #   controller.send(%(current_user), *args, &block)
  168
+            end                                             # end
169 169
           end_eval
170 170
         end
171 171
       end
6  actionpack/lib/action_controller/mime_responds.rb
@@ -145,9 +145,9 @@ def self.generate_method_for_mime(mime)
145 145
         sym = mime.is_a?(Symbol) ? mime : mime.to_sym
146 146
         const = sym.to_s.upcase
147 147
         class_eval <<-RUBY, __FILE__, __LINE__ + 1
148  
-          def #{sym}(&block)                          # def html(&block)
149  
-            custom(Mime::#{const}, &block)            #   custom(Mime::HTML, &block)
150  
-          end                                         # end
  148
+          def #{sym}(&block)                # def html(&block)
  149
+            custom(Mime::#{const}, &block)  #   custom(Mime::HTML, &block)
  150
+          end                               # end
151 151
         RUBY
152 152
       end
153 153
 
18  actionpack/lib/action_controller/polymorphic_routes.rb
@@ -118,13 +118,17 @@ def polymorphic_path(record_or_hash_or_array, options = {})
118 118
 
119 119
     %w(edit new).each do |action|
120 120
       module_eval <<-EOT, __FILE__, __LINE__
121  
-        def #{action}_polymorphic_url(record_or_hash, options = {})
122  
-          polymorphic_url(record_or_hash, options.merge(:action => "#{action}"))
123  
-        end
124  
-
125  
-        def #{action}_polymorphic_path(record_or_hash, options = {})
126  
-          polymorphic_url(record_or_hash, options.merge(:action => "#{action}", :routing_type => :path))
127  
-        end
  121
+        def #{action}_polymorphic_url(record_or_hash, options = {})         # def edit_polymorphic_url(record_or_hash, options = {})
  122
+          polymorphic_url(                                                  #   polymorphic_url(
  123
+            record_or_hash,                                                 #     record_or_hash,
  124
+            options.merge(:action => "#{action}"))                          #     options.merge(:action => "edit"))
  125
+        end                                                                 # end
  126
+                                                                            #
  127
+        def #{action}_polymorphic_path(record_or_hash, options = {})        # def edit_polymorphic_path(record_or_hash, options = {})
  128
+          polymorphic_url(                                                  #   polymorphic_url(
  129
+            record_or_hash,                                                 #     record_or_hash,
  130
+            options.merge(:action => "#{action}", :routing_type => :path))  #     options.merge(:action => "edit", :routing_type => :path))
  131
+        end                                                                 # end
128 132
       EOT
129 133
     end
130 134
 
2  actionpack/lib/action_controller/request.rb
@@ -295,7 +295,7 @@ def raw_host_with_port
295 295
       if forwarded = env["HTTP_X_FORWARDED_HOST"]
296 296
         forwarded.split(/,\s?/).last
297 297
       else
298  
-        env['HTTP_HOST'] || env['SERVER_NAME'] || "#{env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
  298
+        env['HTTP_HOST'] || "#{env['SERVER_NAME'] || env['SERVER_ADDR']}:#{env['SERVER_PORT']}"
299 299
       end
300 300
     end
301 301
 
61  actionpack/lib/action_controller/routing/route_set.rb
@@ -145,10 +145,10 @@ def named_helper_module_eval(code, *args)
145 145
           def define_hash_access(route, name, kind, options)
146 146
             selector = hash_access_name(name, kind)
147 147
             named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
148  
-              def #{selector}(options = nil)
149  
-                options ? #{options.inspect}.merge(options) : #{options.inspect}
150  
-              end
151  
-              protected :#{selector}
  148
+              def #{selector}(options = nil)                                      # def hash_for_users_url(options = nil)
  149
+                options ? #{options.inspect}.merge(options) : #{options.inspect}  #   options ? {:only_path=>false}.merge(options) : {:only_path=>false}
  150
+              end                                                                 # end
  151
+              protected :#{selector}                                              # protected :hash_for_users_url
152 152
             end_eval
153 153
             helpers << selector
154 154
           end
@@ -173,32 +173,33 @@ def define_url_helper(route, name, kind, options)
173 173
             #   foo_url(bar, baz, bang, :sort_by => 'baz')
174 174
             #
175 175
             named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
176  
-              def #{selector}(*args)
177  
-
178  
-                #{generate_optimisation_block(route, kind)}
179  
-
180  
-                opts = if args.empty? || Hash === args.first
181  
-                  args.first || {}
182  
-                else
183  
-                  options = args.extract_options!
184  
-                  args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|
185  
-                    h[k] = v
186  
-                    h
187  
-                  end
188  
-                  options.merge(args)
189  
-                end
190  
-
191  
-                url_for(#{hash_access_method}(opts))
192  
-                
193  
-              end
194  
-              #Add an alias to support the now deprecated formatted_* URL.
195  
-              def formatted_#{selector}(*args)
196  
-                ActiveSupport::Deprecation.warn(
197  
-                  "formatted_#{selector}() has been deprecated. please pass format to the standard" +
198  
-                  "#{selector}() method instead.", caller)
199  
-                #{selector}(*args)
200  
-              end
201  
-              protected :#{selector}
  176
+              def #{selector}(*args)                                                        # def users_url(*args)
  177
+                                                                                            #
  178
+                #{generate_optimisation_block(route, kind)}                                 #   #{generate_optimisation_block(route, kind)}
  179
+                                                                                            #
  180
+                opts = if args.empty? || Hash === args.first                                #   opts = if args.empty? || Hash === args.first
  181
+                  args.first || {}                                                          #     args.first || {}
  182
+                else                                                                        #   else
  183
+                  options = args.extract_options!                                           #     options = args.extract_options!
  184
+                  args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|  #     args = args.zip([]).inject({}) do |h, (v, k)|
  185
+                    h[k] = v                                                                #       h[k] = v
  186
+                    h                                                                       #       h
  187
+                  end                                                                       #     end
  188
+                  options.merge(args)                                                       #     options.merge(args)
  189
+                end                                                                         #   end
  190
+                                                                                            #
  191
+                url_for(#{hash_access_method}(opts))                                        #   url_for(hash_for_users_url(opts))
  192
+                                                                                            #
  193
+              end                                                                           # end
  194
+              #Add an alias to support the now deprecated formatted_* URL.                  # #Add an alias to support the now deprecated formatted_* URL.
  195
+              def formatted_#{selector}(*args)                                              # def formatted_users_url(*args)
  196
+                ActiveSupport::Deprecation.warn(                                            #   ActiveSupport::Deprecation.warn(
  197
+                  "formatted_#{selector}() has been deprecated. " +                         #     "formatted_users_url() has been deprecated. " +
  198
+                  "please pass format to the standard" +                                    #     "please pass format to the standard" +
  199
+                  "#{selector}() method instead.", caller)                                  #     "users_url() method instead.", caller)
  200
+                #{selector}(*args)                                                          #   users_url(*args)
  201
+              end                                                                           # end
  202
+              protected :#{selector}                                                        # protected :users_url
202 203
             end_eval
203 204
             helpers << selector
204 205
           end
6  actionpack/lib/action_controller/test_process.rb
@@ -33,11 +33,7 @@ class TestRequest < Request #:nodoc:
33 33
     attr_accessor :host
34 34
 
35 35
     def initialize
36  
-      env = Rack::MockRequest.env_for("/")
37  
-
38  
-      # TODO: Fix Request to assume env['SERVER_ADDR'] doesn't contain port number
39  
-      env['SERVER_ADDR'] = env.delete("SERVER_NAME")
40  
-      super(env)
  36
+      super(Rack::MockRequest.env_for("/"))
41 37
 
42 38
       @query_parameters   = {}
43 39
       @session            = TestSession.new
10  actionpack/lib/action_view/helpers/form_helper.rb
@@ -737,9 +737,13 @@ def initialize(object_name, object, template, options, proc)
737 737
 
738 738
       (field_helpers - %w(label check_box radio_button fields_for)).each do |selector|
739 739
         src = <<-end_src
740  
-          def #{selector}(method, options = {})
741  
-            @template.send(#{selector.inspect}, @object_name, method, objectify_options(options))
742  
-          end
  740
+          def #{selector}(method, options = {})  # def text_field(method, options = {})
  741
+            @template.send(                      #   @template.send(
  742
+              #{selector.inspect},               #     "text_field",
  743
+              @object_name,                      #     @object_name,
  744
+              method,                            #     method,
  745
+              objectify_options(options))        #     objectify_options(options))
  746
+          end                                    # end
743 747
         end_src
744 748
         class_eval src, __FILE__, __LINE__
745 749
       end
4  actionpack/test/controller/rack_test.rb
@@ -4,7 +4,7 @@ class BaseRackTest < Test::Unit::TestCase
4 4
   def setup
5 5
     @env = {
6 6
       "HTTP_MAX_FORWARDS" => "10",
7  
-      "SERVER_NAME" => "glu.ttono.us:8007",
  7
+      "SERVER_NAME" => "glu.ttono.us",
8 8
       "FCGI_ROLE" => "RESPONDER",
9 9
       "AUTH_TYPE" => "Basic",
10 10
       "HTTP_X_FORWARDED_HOST" => "glu.ttono.us",
@@ -145,7 +145,7 @@ def test_cgi_environment_variables
145 145
     assert_equal "kevin", @request.remote_user
146 146
     assert_equal :get, @request.request_method
147 147
     assert_equal "/dispatch.fcgi", @request.script_name
148  
-    assert_equal "glu.ttono.us:8007", @request.server_name
  148
+    assert_equal "glu.ttono.us", @request.server_name
149 149
     assert_equal 8007, @request.server_port
150 150
     assert_equal "HTTP/1.1", @request.server_protocol
151 151
     assert_equal "lighttpd", @request.server_software
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *2.3.0/3.0*
2 2
 
  3
+* Added dynamic scopes ala dynamic finders #1648 [Yaroslav Markin]
  4
+
3 5
 * Fixed that ActiveRecord::Base#new_record? should return false (not nil) for existing records #1219 [Yaroslav Markin]
4 6
 
5 7
 * I18n the word separator for error messages. Introduces the activerecord.errors.format.separator translation key.  #1294 [Akira Matsuda]
1  activerecord/lib/active_record.rb
@@ -51,6 +51,7 @@ def self.load_all!
51 51
   autoload :Callbacks, 'active_record/callbacks'
52 52
   autoload :Dirty, 'active_record/dirty'
53 53
   autoload :DynamicFinderMatch, 'active_record/dynamic_finder_match'
  54
+  autoload :DynamicScopeMatch, 'active_record/dynamic_scope_match'
54 55
   autoload :Migration, 'active_record/migration'
55 56
   autoload :Migrator, 'active_record/migration'
56 57
   autoload :NamedScope, 'active_record/named_scope'
36  activerecord/lib/active_record/associations.rb
@@ -1216,11 +1216,11 @@ def has_and_belongs_to_many(association_id, options = {}, &extension)
1216 1216
         # callbacks will be executed after the association is wiped out.
1217 1217
         old_method = "destroy_without_habtm_shim_for_#{reflection.name}"
1218 1218
         class_eval <<-end_eval unless method_defined?(old_method)
1219  
-          alias_method :#{old_method}, :destroy_without_callbacks
1220  
-          def destroy_without_callbacks
1221  
-            #{reflection.name}.clear
1222  
-            #{old_method}
1223  
-          end
  1219
+          alias_method :#{old_method}, :destroy_without_callbacks  # alias_method :destroy_without_habtm_shim_for_posts, :destroy_without_callbacks
  1220
+          def destroy_without_callbacks                            # def destroy_without_callbacks
  1221
+            #{reflection.name}.clear                               #   posts.clear
  1222
+            #{old_method}                                          #   destroy_without_habtm_shim_for_posts
  1223
+          end                                                      # end
1224 1224
         end_eval
1225 1225
 
1226 1226
         add_association_callbacks(reflection.name, options)
@@ -1463,22 +1463,22 @@ def configure_dependency_for_has_many(reflection, extra_conditions = nil)
1463 1463
                 before_destroy method_name
1464 1464
               when :delete_all
1465 1465
                 module_eval %Q{
1466  
-                  before_destroy do |record|
1467  
-                    delete_all_has_many_dependencies(record,
1468  
-                      "#{reflection.name}",
1469  
-                      #{reflection.class_name},
1470  
-                      %@#{dependent_conditions}@)
1471  
-                  end
  1466
+                  before_destroy do |record|                  # before_destroy do |record|
  1467
+                    delete_all_has_many_dependencies(record,  #   delete_all_has_many_dependencies(record,
  1468
+                      "#{reflection.name}",                   #     "posts",
  1469
+                      #{reflection.class_name},               #     Post,
  1470
+                      %@#{dependent_conditions}@)             #     %@...@) # this is a string literal like %(...)
  1471
+                  end                                         # end
1472 1472
                 }
1473 1473
               when :nullify
1474 1474
                 module_eval %Q{
1475  
-                  before_destroy do |record|
1476  
-                    nullify_has_many_dependencies(record,
1477  
-                      "#{reflection.name}",
1478  
-                      #{reflection.class_name},
1479  
-                      "#{reflection.primary_key_name}",
1480  
-                      %@#{dependent_conditions}@)
1481  
-                  end
  1475
+                  before_destroy do |record|                  # before_destroy do |record|
  1476
+                    nullify_has_many_dependencies(record,     #   nullify_has_many_dependencies(record,
  1477
+                      "#{reflection.name}",                   #     "posts",
  1478
+                      #{reflection.class_name},               #     Post,
  1479
+                      "#{reflection.primary_key_name}",       #     "user_id",
  1480
+                      %@#{dependent_conditions}@)             #     %@...@) # this is a string literal like %(...)
  1481
+                  end                                         # end
1482 1482
                 }
1483 1483
               else
1484 1484
                 raise ArgumentError, "The :dependent option expects either :destroy, :delete_all, or :nullify (#{reflection.options[:dependent].inspect})"
73  activerecord/lib/active_record/base.rb
@@ -1456,7 +1456,10 @@ def abstract_class?
1456 1456
       def respond_to?(method_id, include_private = false)
1457 1457
         if match = DynamicFinderMatch.match(method_id)
1458 1458
           return true if all_attributes_exists?(match.attribute_names)
  1459
+        elsif match = DynamicScopeMatch.match(method_id)
  1460
+          return true if all_attributes_exists?(match.attribute_names)
1459 1461
         end
  1462
+        
1460 1463
         super
1461 1464
       end
1462 1465
 
@@ -1809,7 +1812,11 @@ def undecorated_table_name(class_name = base_class.name)
1809 1812
         # This also enables you to initialize a record if it is not found, such as find_or_initialize_by_amount(amount)
1810 1813
         # or find_or_create_by_user_and_password(user, password).
1811 1814
         #
1812  
-        # Each dynamic finder or initializer/creator is also defined in the class after it is first invoked, so that future
  1815
+        # Also enables dynamic scopes like scoped_by_user_name(user_name) and scoped_by_user_name_and_password(user_name, password) that
  1816
+        # are turned into scoped(:conditions => ["user_name = ?", user_name]) and scoped(:conditions => ["user_name = ? AND password = ?", user_name, password])
  1817
+        # respectively.
  1818
+        #
  1819
+        # Each dynamic finder, scope or initializer/creator is also defined in the class after it is first invoked, so that future
1813 1820
         # attempts to use it do not run through method_missing.
1814 1821
         def method_missing(method_id, *arguments, &block)
1815 1822
           if match = DynamicFinderMatch.match(method_id)
@@ -1818,10 +1825,31 @@ def method_missing(method_id, *arguments, &block)
1818 1825
             if match.finder?
1819 1826
               finder = match.finder
1820 1827
               bang = match.bang?
  1828
+              # def self.find_by_login_and_activated(*args)
  1829
+              #   options = args.extract_options!
  1830
+              #   attributes = construct_attributes_from_arguments(
  1831
+              #     [:login,:activated],
  1832
+              #     args
  1833
+              #   )
  1834
+              #   finder_options = { :conditions => attributes }
  1835
+              #   validate_find_options(options)
  1836
+              #   set_readonly_option!(options)
  1837
+              #
  1838
+              #   if options[:conditions]
  1839
+              #     with_scope(:find => finder_options) do
  1840
+              #       find(:first, options)
  1841
+              #     end
  1842
+              #   else
  1843
+              #     find(:first, options.merge(finder_options))
  1844
+              #   end
  1845
+              # end
1821 1846
               self.class_eval %{
1822 1847
                 def self.#{method_id}(*args)
1823 1848
                   options = args.extract_options!
1824  
-                  attributes = construct_attributes_from_arguments([:#{attribute_names.join(',:')}], args)
  1849
+                  attributes = construct_attributes_from_arguments(
  1850
+                    [:#{attribute_names.join(',:')}],
  1851
+                    args
  1852
+                  )
1825 1853
                   finder_options = { :conditions => attributes }
1826 1854
                   validate_find_options(options)
1827 1855
                   set_readonly_option!(options)
@@ -1839,6 +1867,31 @@ def self.#{method_id}(*args)
1839 1867
               send(method_id, *arguments)
1840 1868
             elsif match.instantiator?
1841 1869
               instantiator = match.instantiator
  1870
+              # def self.find_or_create_by_user_id(*args)
  1871
+              #   guard_protected_attributes = false
  1872
+              #
  1873
+              #   if args[0].is_a?(Hash)
  1874
+              #     guard_protected_attributes = true
  1875
+              #     attributes = args[0].with_indifferent_access
  1876
+              #     find_attributes = attributes.slice(*[:user_id])
  1877
+              #   else
  1878
+              #     find_attributes = attributes = construct_attributes_from_arguments([:user_id], args)
  1879
+              #   end
  1880
+              #
  1881
+              #   options = { :conditions => find_attributes }
  1882
+              #   set_readonly_option!(options)
  1883
+              #
  1884
+              #   record = find(:first, options)
  1885
+              #
  1886
+              #   if record.nil?
  1887
+              #     record = self.new { |r| r.send(:attributes=, attributes, guard_protected_attributes) }
  1888
+              #     yield(record) if block_given?
  1889
+              #     record.save
  1890
+              #     record
  1891
+              #   else
  1892
+              #     record
  1893
+              #   end
  1894
+              # end
1842 1895
               self.class_eval %{
1843 1896
                 def self.#{method_id}(*args)
1844 1897
                   guard_protected_attributes = false
@@ -1868,6 +1921,22 @@ def self.#{method_id}(*args)
1868 1921
               }, __FILE__, __LINE__
1869 1922
               send(method_id, *arguments, &block)
1870 1923
             end
  1924
+          elsif match = DynamicScopeMatch.match(method_id)
  1925
+            attribute_names = match.attribute_names
  1926
+            super unless all_attributes_exists?(attribute_names)
  1927
+            if match.scope?
  1928
+              self.class_eval %{
  1929
+                def self.#{method_id}(*args)                        # def self.scoped_by_user_name_and_password(*args)
  1930
+                  options = args.extract_options!                   #   options = args.extract_options!
  1931
+                  attributes = construct_attributes_from_arguments( #   attributes = construct_attributes_from_arguments(
  1932
+                    [:#{attribute_names.join(',:')}], args          #     [:user_name, :password], args
  1933
+                  )                                                 #   )
  1934
+                                                                    # 
  1935
+                  scoped(:conditions => attributes)                 #   scoped(:conditions => attributes)
  1936
+                end                                                 # end
  1937
+              }, __FILE__, __LINE__
  1938
+              send(method_id, *arguments)
  1939
+            end
1871 1940
           else
1872 1941
             super
1873 1942
           end
12  activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -14,12 +14,12 @@ def included(base)
14 14
         def dirties_query_cache(base, *method_names)
15 15
           method_names.each do |method_name|
16 16
             base.class_eval <<-end_code, __FILE__, __LINE__
17  
-              def #{method_name}_with_query_dirty(*args)
18  
-                clear_query_cache if @query_cache_enabled
19  
-                #{method_name}_without_query_dirty(*args)
20  
-              end
21  
-
22  
-              alias_method_chain :#{method_name}, :query_dirty
  17
+              def #{method_name}_with_query_dirty(*args)        # def update_with_query_dirty(*args)
  18
+                clear_query_cache if @query_cache_enabled       #   clear_query_cache if @query_cache_enabled
  19
+                #{method_name}_without_query_dirty(*args)       #   update_without_query_dirty(*args)
  20
+              end                                               # end
  21
+                                                                #
  22
+              alias_method_chain :#{method_name}, :query_dirty  # alias_method_chain :update, :query_dirty
23 23
             end_code
24 24
           end
25 25
         end
48  activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -476,12 +476,12 @@ def column(name, type, options = {})
476 476
 
477 477
       %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
478 478
         class_eval <<-EOV
479  
-          def #{column_type}(*args)
480  
-            options = args.extract_options!
481  
-            column_names = args
482  
-
483  
-            column_names.each { |name| column(name, '#{column_type}', options) }
484  
-          end
  479
+          def #{column_type}(*args)                                               # def string(*args)
  480
+            options = args.extract_options!                                       #   options = args.extract_options!
  481
+            column_names = args                                                   #   column_names = args
  482
+                                                                                  #
  483
+            column_names.each { |name| column(name, '#{column_type}', options) }  #   column_names.each { |name| column(name, 'string', options) }
  484
+          end                                                                     # end
485 485
         EOV
486 486
       end
487 487
 
@@ -676,24 +676,24 @@ def remove_references(*args)
676 676
       #  t.string(:goat, :sheep)
677 677
       %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
678 678
         class_eval <<-EOV
679  
-          def #{column_type}(*args)
680  
-            options = args.extract_options!
681  
-            column_names = args
682  
-
683  
-            column_names.each do |name|
684  
-              column = ColumnDefinition.new(@base, name, '#{column_type}')
685  
-              if options[:limit]
686  
-                column.limit = options[:limit]
687  
-              elsif native['#{column_type}'.to_sym].is_a?(Hash)
688  
-                column.limit = native['#{column_type}'.to_sym][:limit]
689  
-              end
690  
-              column.precision = options[:precision]
691  
-              column.scale = options[:scale]
692  
-              column.default = options[:default]
693  
-              column.null = options[:null]
694  
-              @base.add_column(@table_name, name, column.sql_type, options)
695  
-            end
696  
-          end
  679
+          def #{column_type}(*args)                                          # def string(*args)
  680
+            options = args.extract_options!                                  #   options = args.extract_options!
  681
+            column_names = args                                              #   column_names = args
  682
+                                                                             #
  683
+            column_names.each do |name|                                      #   column_names.each do |name|
  684
+              column = ColumnDefinition.new(@base, name, '#{column_type}')   #     column = ColumnDefinition.new(@base, name, 'string')
  685
+              if options[:limit]                                             #     if options[:limit]
  686
+                column.limit = options[:limit]                               #       column.limit = options[:limit]
  687
+              elsif native['#{column_type}'.to_sym].is_a?(Hash)              #     elsif native['string'.to_sym].is_a?(Hash)
  688
+                column.limit = native['#{column_type}'.to_sym][:limit]       #       column.limit = native['string'.to_sym][:limit]
  689
+              end                                                            #     end
  690
+              column.precision = options[:precision]                         #     column.precision = options[:precision]
  691
+              column.scale = options[:scale]                                 #     column.scale = options[:scale]
  692
+              column.default = options[:default]                             #     column.default = options[:default]
  693
+              column.null = options[:null]                                   #     column.null = options[:null]
  694
+              @base.add_column(@table_name, name, column.sql_type, options)  #     @base.add_column(@table_name, name, column.sql_type, options)
  695
+            end                                                              #   end
  696
+          end                                                                # end
697 697
         EOV
698 698
       end
699 699
 
24  activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -13,23 +13,25 @@ def self.define_all_hashes_method!
13 13
     # C driver >= 2.7 returns null values in each_hash
14 14
     if Mysql.const_defined?(:VERSION) && (Mysql::VERSION.is_a?(String) || Mysql::VERSION >= 20700)
15 15
       target.class_eval <<-'end_eval'
16  
-      def all_hashes
17  
-        rows = []
18  
-        each_hash { |row| rows << row }
19  
-        rows
20  
-      end
  16
+      def all_hashes                     # def all_hashes
  17
+        rows = []                        #   rows = []
  18
+        each_hash { |row| rows << row }  #   each_hash { |row| rows << row }
  19
+        rows                             #   rows
  20
+      end                                # end
21 21
       end_eval
22 22
 
23 23
     # adapters before 2.7 don't have a version constant
24 24
     # and don't return null values in each_hash
25 25
     else
26 26
       target.class_eval <<-'end_eval'
27  
-      def all_hashes
28  
-        rows = []
29  
-        all_fields = fetch_fields.inject({}) { |fields, f| fields[f.name] = nil; fields }
30  
-        each_hash { |row| rows << all_fields.dup.update(row) }
31  
-        rows
32  
-      end
  27
+      def all_hashes                                            # def all_hashes
  28
+        rows = []                                               #   rows = []
  29
+        all_fields = fetch_fields.inject({}) { |fields, f|      #   all_fields = fetch_fields.inject({}) { |fields, f|
  30
+          fields[f.name] = nil; fields                          #     fields[f.name] = nil; fields
  31
+        }                                                       #   }
  32
+        each_hash { |row| rows << all_fields.dup.update(row) }  #   each_hash { |row| rows << all_fields.dup.update(row) }
  33
+        rows                                                    #   rows
  34
+      end                                                       # end
33 35
       end_eval
34 36
     end
35 37
 
14  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -950,13 +950,13 @@ def connect
950 950
           # should know about this but can't detect it there, so deal with it here.
951 951
           money_precision = (postgresql_version >= 80300) ? 19 : 10
952 952
           PostgreSQLColumn.module_eval(<<-end_eval)
953  
-            def extract_precision(sql_type)
954  
-              if sql_type =~ /^money$/
955  
-                #{money_precision}
956  
-              else
957  
-                super
958  
-              end
959  
-            end
  953
+            def extract_precision(sql_type)  # def extract_precision(sql_type)
  954
+              if sql_type =~ /^money$/       #   if sql_type =~ /^money$/
  955
+                #{money_precision}           #     19
  956
+              else                           #   else
  957
+                super                        #     super
  958
+              end                            #   end
  959
+            end                              # end
960 960
           end_eval
961 961
 
962 962
           configure_connection
2  activerecord/lib/active_record/dirty.rb
@@ -174,7 +174,7 @@ def alias_attribute_with_dirty(new_name, old_name)
174 174
         alias_attribute_without_dirty(new_name, old_name)
175 175
         DIRTY_SUFFIXES.each do |suffix|
176 176
           module_eval <<-STR, __FILE__, __LINE__+1
177  
-            def #{new_name}#{suffix}; self.#{old_name}#{suffix}; end
  177
+            def #{new_name}#{suffix}; self.#{old_name}#{suffix}; end  # def subject_changed?; self.title_changed?; end
178 178
           STR
179 179
         end
180 180
       end
25  activerecord/lib/active_record/dynamic_scope_match.rb
... ...
@@ -0,0 +1,25 @@
  1
+module ActiveRecord
  2
+  class DynamicScopeMatch
  3
+    def self.match(method)
  4
+      ds_match = self.new(method)
  5
+      ds_match.scope ? ds_match : nil
  6
+    end
  7
+
  8
+    def initialize(method)
  9
+      @scope = true
  10
+      case method.to_s
  11
+      when /^scoped_by_([_a-zA-Z]\w*)$/
  12
+        names = $1
  13
+      else
  14
+        @scope = nil
  15
+      end
  16
+      @attribute_names = names && names.split('_and_')
  17
+    end
  18
+
  19
+    attr_reader :scope, :attribute_names
  20
+
  21
+    def scope?
  22
+      !@scope.nil?
  23
+    end
  24
+  end
  25
+end
20  activerecord/test/cases/named_scope_test.rb
@@ -278,3 +278,23 @@ def test_chaining_with_duplicate_joins
278 278
     assert_equal post.comments.size, Post.scoped(:joins => join).scoped(:joins => join, :conditions => "posts.id = #{post.id}").size
279 279
   end
280 280
 end
  281
+
  282
+class DynamicScopeMatchTest < ActiveRecord::TestCase  
  283
+  def test_scoped_by_no_match
  284
+    assert_nil ActiveRecord::DynamicScopeMatch.match("not_scoped_at_all")
  285
+  end
  286
+
  287
+  def test_scoped_by
  288
+    match = ActiveRecord::DynamicScopeMatch.match("scoped_by_age_and_sex_and_location")
  289
+    assert_not_nil match
  290
+    assert match.scope?
  291
+    assert_equal %w(age sex location), match.attribute_names
  292
+  end
  293
+end
  294
+
  295
+class DynamicScopeTest < ActiveRecord::TestCase
  296
+  def test_dynamic_scope
  297
+    assert_equal Post.scoped_by_author_id(1).find(1), Post.find(1)
  298
+    assert_equal Post.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, Post.find(:first, :conditions => { :author_id => 1, :title => "Welcome to the weblog"})
  299
+  end
  300
+end
8  activeresource/lib/active_resource/http_mock.rb
@@ -54,6 +54,9 @@ def initialize(responses)
54 54
       end
55 55
 
56 56
       for method in [ :post, :put, :get, :delete, :head ]
  57
+        # def post(path, request_headers = {}, body = nil, status = 200, response_headers = {})
  58
+        #   @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
  59
+        # end
57 60
         module_eval <<-EOE, __FILE__, __LINE__
58 61
           def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
59 62
             @responses[Request.new(:#{method}, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
@@ -118,6 +121,11 @@ def reset!
118 121
     end
119 122
 
120 123
     for method in [ :post, :put ]
  124
+      # def post(path, body, headers)
  125
+      #   request = ActiveResource::Request.new(:post, path, body, headers)
  126
+      #   self.class.requests << request
  127
+      #   self.class.responses[request] || raise(InvalidRequestError.new("No response recorded for #{request}"))
  128
+      # end
121 129
       module_eval <<-EOE, __FILE__, __LINE__
122 130
         def #{method}(path, body, headers)
123 131
           request = ActiveResource::Request.new(:#{method}, path, body, headers)
32  activesupport/lib/active_support/callbacks.rb
@@ -210,20 +210,24 @@ module ClassMethods
210 210
       def define_callbacks(*callbacks)
211 211
         callbacks.each do |callback|
212 212
           class_eval <<-"end_eval", __FILE__, __LINE__ + 1
213  
-            def self.#{callback}(*methods, &block)                                                 # def self.validate_on_create(*methods, &block)
214  
-              callbacks = CallbackChain.build(:#{callback}, *methods, &block)                      #   callbacks = CallbackChain.build(:validate_on_create, *methods, &block)
215  
-              (@#{callback}_callbacks ||= CallbackChain.new).concat callbacks                      #   (@validate_on_create_callbacks ||= CallbackChain.new).concat callbacks
216  
-            end                                                                                    # end
217  
-
218  
-            def self.#{callback}_callback_chain                                                    # def self.validate_on_create_callback_chain
219  
-              @#{callback}_callbacks ||= CallbackChain.new                                         #   @validate_on_create_callbacks ||= CallbackChain.new
220  
-                                                                                                   #
221  
-              if superclass.respond_to?(:#{callback}_callback_chain)                               #   if superclass.respond_to?(:validate_on_create_callback_chain)  
222  
-                CallbackChain.new(superclass.#{callback}_callback_chain + @#{callback}_callbacks)  #     CallbackChain.new(superclass.validate_on_create_callback_chain + @validate_on_create_callbacks)
223  
-              else                                                                                 #   else
224  
-                @#{callback}_callbacks                                                             #     @validate_on_create_callbacks
225  
-              end                                                                                  #   end
226  
-            end                                                                                    # end
  213
+            def self.#{callback}(*methods, &block)                             # def self.before_save(*methods, &block)
  214
+              callbacks = CallbackChain.build(:#{callback}, *methods, &block)  #   callbacks = CallbackChain.build(:before_save, *methods, &block)
  215
+              @#{callback}_callbacks ||= CallbackChain.new                     #   @before_save_callbacks ||= CallbackChain.new
  216
+              @#{callback}_callbacks.concat callbacks                          #   @before_save_callbacks.concat callbacks
  217
+            end                                                                # end
  218
+                                                                               #
  219
+            def self.#{callback}_callback_chain                                # def self.before_save_callback_chain
  220
+              @#{callback}_callbacks ||= CallbackChain.new                     #   @before_save_callbacks ||= CallbackChain.new
  221
+                                                                               #
  222
+              if superclass.respond_to?(:#{callback}_callback_chain)           #   if superclass.respond_to?(:before_save_callback_chain)
  223
+                CallbackChain.new(                                             #     CallbackChain.new(
  224
+                  superclass.#{callback}_callback_chain +                      #       superclass.before_save_callback_chain +
  225
+                  @#{callback}_callbacks                                       #       @before_save_callbacks
  226
+                )                                                              #     )
  227
+              else                                                             #   else
  228
+                @#{callback}_callbacks                                         #     @before_save_callbacks
  229
+              end                                                              #   end
  230
+            end                                                                # end
227 231
           end_eval
228 232
         end
229 233
       end
48  activesupport/lib/active_support/core_ext/class/attribute_accessors.rb
@@ -11,17 +11,17 @@ def cattr_reader(*syms)
11 11
     syms.flatten.each do |sym|
12 12
       next if sym.is_a?(Hash)
13 13
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
14  
-        unless defined? @@#{sym}   # unless defined @@property
15  
-          @@#{sym} = nil           #   @@property = nil
16  
-        end                        # end
17  
-
18  
-        def self.#{sym}            # def self.property
19  
-          @@#{sym}                 #   @@property
20  
-        end                        # end
21  
-
22  
-        def #{sym}                 # def property
23  
-          @@#{sym}                 #   @@property
24  
-        end                        # end
  14
+        unless defined? @@#{sym}  # unless defined? @@hair_colors
  15
+          @@#{sym} = nil          #   @@hair_colors = nil
  16
+        end                       # end
  17
+                                  #
  18
+        def self.#{sym}           # def self.hair_colors
  19
+          @@#{sym}                #   @@hair_colors
  20
+        end                       # end
  21
+                                  #
  22
+        def #{sym}                # def hair_colors
  23
+          @@#{sym}                #   @@hair_colors
  24
+        end                       # end
25 25
       EOS
26 26
     end
27 27
   end
@@ -30,19 +30,19 @@ def cattr_writer(*syms)
30 30
     options = syms.extract_options!
31 31
     syms.flatten.each do |sym|
32 32
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
33  
-        unless defined? @@#{sym}   # unless defined? @@property
34  
-          @@#{sym} = nil           #   @@property = nil
35  
-        end                        # end
36  
-                                   
37  
-        def self.#{sym}=(obj)      # def self.property=(obj)
38  
-          @@#{sym} = obj           #   @@property
39  
-        end                        # end
40  
-                                   
41  
-        #{"                        
42  
-        def #{sym}=(obj)           # def property=(obj)
43  
-          @@#{sym} = obj           #   @@property = obj
44  
-        end                        # end
45  
-        " unless options[:instance_writer] == false }
  33
+        unless defined? @@#{sym}                       # unless defined? @@hair_colors
  34
+          @@#{sym} = nil                               #   @@hair_colors = nil
  35
+        end                                            # end
  36
+                                                       #
  37
+        def self.#{sym}=(obj)                          # def self.hair_colors=(obj)
  38
+          @@#{sym} = obj                               #   @@hair_colors = obj
  39
+        end                                            # end
  40
+                                                       #
  41
+        #{"                                            #
  42
+        def #{sym}=(obj)                               # def hair_colors=(obj)
  43
+          @@#{sym} = obj                               #   @@hair_colors = obj
  44
+        end                                            # end
  45
+        " unless options[:instance_writer] == false }  # # instance writer above is generated unless options[:instance_writer] == false
46 46
       EOS
47 47
     end
48 48
   end
33  activesupport/lib/active_support/core_ext/class/delegating_attributes.rb
@@ -9,22 +9,23 @@ def superclass_delegating_reader(*names)
9 9
     class_name_to_stop_searching_on = self.superclass.name.blank? ? "Object" : self.superclass.name
10 10
     names.each do |name|
11 11
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
12  
-      def self.#{name}                                                                            # def self.property
13  
-        if defined?(@#{name})                                                                     #   if defined?(@property)
14  
-          @#{name}                                                                                #     @property
15  
-        elsif superclass < #{class_name_to_stop_searching_on} && superclass.respond_to?(:#{name}) #   elseif superclass < Object && superclass.respond_to?(:property)
16  
-          superclass.#{name}                                                                      #     superclass.property
17  
-        end                                                                                       #   end
18  
-      end                                                                                         # end
19  
-      def #{name}                                                                                 # def property
20  
-        self.class.#{name}                                                                        #   self.class.property
21  
-      end                                                                                         # end
22  
-      def self.#{name}?                                                                           # def self.property?
23  
-        !!#{name}                                                                                 #   !!property
24  
-      end                                                                                         # end
25  
-      def #{name}?                                                                                # def property?
26  
-        !!#{name}                                                                                 #   !!property
27  
-      end                                                                                         # end
  12
+      def self.#{name}                                            # def self.only_reader
  13
+        if defined?(@#{name})                                     #   if defined?(@only_reader)
  14
+          @#{name}                                                #     @only_reader
  15
+        elsif superclass < #{class_name_to_stop_searching_on} &&  #   elsif superclass < Object &&
  16
+              superclass.respond_to?(:#{name})                    #         superclass.respond_to?(:only_reader)
  17
+          superclass.#{name}                                      #     superclass.only_reader
  18
+        end                                                       #   end
  19
+      end                                                         # end
  20
+      def #{name}                                                 # def only_reader
  21
+        self.class.#{name}                                        #   self.class.only_reader
  22
+      end                                                         # end
  23
+      def self.#{name}?                                           # def self.only_reader?
  24
+        !!#{name}                                                 #   !!only_reader
  25
+      end                                                         # end
  26
+      def #{name}?                                                # def only_reader?
  27
+        !!#{name}                                                 #   !!only_reader
  28
+      end                                                         # end
28 29
       EOS
29 30
     end
30 31
   end
54  activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
@@ -26,15 +26,15 @@ def class_inheritable_writer(*syms)
26 26
     options = syms.extract_options!
27 27
     syms.each do |sym|
28 28
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
29  
-        def self.#{sym}=(obj)                         # def self.property=(obj)
30  
-          write_inheritable_attribute(:#{sym}, obj)   #   write_inheritable_attribute(:property, obj)
31  
-        end                                           # end
32  
-
33  
-        #{"
34  
-        def #{sym}=(obj)                              # def property=(obj)
35  
-          self.class.#{sym} = obj                     #   self.class.property = obj
36  
-        end                                           # end
37  
-        " unless options[:instance_writer] == false }
  29
+        def self.#{sym}=(obj)                          # def self.color=(obj)
  30
+          write_inheritable_attribute(:#{sym}, obj)    #   write_inheritable_attribute(:color, obj)
  31
+        end                                            # end
  32
+                                                       #
  33
+        #{"                                            #
  34
+        def #{sym}=(obj)                               # def color=(obj)
  35
+          self.class.#{sym} = obj                      #   self.class.color = obj
  36
+        end                                            # end
  37
+        " unless options[:instance_writer] == false }  # # the writer above is generated unless options[:instance_writer] == false
38 38
       EOS
39 39
     end
40 40
   end
@@ -43,15 +43,15 @@ def class_inheritable_array_writer(*syms)
43 43
     options = syms.extract_options!
44 44
     syms.each do |sym|
45 45
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
46  
-        def self.#{sym}=(obj)                         # def self.property=(obj)
47  
-          write_inheritable_array(:#{sym}, obj)       #   write_inheritable_array(:property, obj)
48  
-        end                                           # end
49  
-
50  
-        #{"
51  
-        def #{sym}=(obj)                              # def property=(obj)
52  
-          self.class.#{sym} = obj                     #   self.class.property = obj
53  
-        end                                           # end
54  
-        " unless options[:instance_writer] == false }
  46
+        def self.#{sym}=(obj)                          # def self.levels=(obj)
  47
+          write_inheritable_array(:#{sym}, obj)        #   write_inheritable_array(:levels, obj)
  48
+        end                                            # end
  49
+                                                       #
  50
+        #{"                                            #
  51
+        def #{sym}=(obj)                               # def levels=(obj)
  52
+          self.class.#{sym} = obj                      #   self.class.levels = obj
  53
+        end                                            # end
  54
+        " unless options[:instance_writer] == false }  # # the writer above is generated unless options[:instance_writer] == false
55 55
       EOS
56 56
     end
57 57
   end
@@ -60,15 +60,15 @@ def class_inheritable_hash_writer(*syms)
60 60
     options = syms.extract_options!
61 61
     syms.each do |sym|
62 62
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
63  
-        def self.#{sym}=(obj)                         # def self.property=(obj)
64  
-          write_inheritable_hash(:#{sym}, obj)        #   write_inheritable_hash(:property, obj)
65  
-        end                                           # end
66  
-
67  
-        #{"
68  
-        def #{sym}=(obj)                              # def property=(obj)
69  
-          self.class.#{sym} = obj                     #   self.class.property = obj
70  
-        end                                           # end
71  
-        " unless options[:instance_writer] == false }
  63
+        def self.#{sym}=(obj)                          # def self.nicknames=(obj)
  64
+          write_inheritable_hash(:#{sym}, obj)         #   write_inheritable_hash(:nicknames, obj)
  65
+        end                                            # end
  66
+                                                       #
  67
+        #{"                                            #
  68
+        def #{sym}=(obj)                               # def nicknames=(obj)
  69
+          self.class.#{sym} = obj                      #   self.class.nicknames = obj
  70
+        end                                            # end
  71
+        " unless options[:instance_writer] == false }  # # the writer above is generated unless options[:instance_writer] == false
72 72
       EOS
73 73
     end
74 74
   end
12  activesupport/lib/active_support/core_ext/logger.rb
@@ -3,12 +3,12 @@
3 3
 class Logger
4 4
   def self.define_around_helper(level)
5 5
     module_eval <<-end_eval
6  
-      def around_#{level}(before_message, after_message, &block)
7  
-        self.#{level}(before_message)
8  
-        return_value = block.call(self)
9  
-        self.#{level}(after_message)
10  
-        return return_value
11  
-      end
  6
+      def around_#{level}(before_message, after_message, &block)  # def around_debug(before_message, after_message, &block)
  7
+        self.#{level}(before_message)                             #   self.debug(before_message)
  8
+        return_value = block.call(self)                           #   return_value = block.call(self)
  9
+        self.#{level}(after_message)                              #   self.debug(after_message)
  10
+        return return_value                                       #   return return_value
  11
+      end                                                         # end
12 12
     end_eval
13 13
   end
14 14
   [:debug, :info, :error, :fatal].each {|level| define_around_helper(level) }
6  activesupport/lib/active_support/core_ext/module/aliasing.rb
@@ -64,9 +64,9 @@ def alias_method_chain(target, feature)
64 64
       #   e.title    # => "Megastars"
65 65
       def alias_attribute(new_name, old_name)
66 66
         module_eval <<-STR, __FILE__, __LINE__+1
67  
-          def #{new_name}; self.#{old_name}; end
68  
-          def #{new_name}?; self.#{old_name}?; end
69  
-          def #{new_name}=(v); self.#{old_name} = v; end
  67
+          def #{new_name}; self.#{old_name}; end          # def subject; self.title; end
  68
+          def #{new_name}?; self.#{old_name}?; end        # def subject?; self.title?; end
  69
+          def #{new_name}=(v); self.#{old_name} = v; end  # def subject=(v); self.title = v; end
70 70
         STR
71 71
       end
72 72
     end
8  activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
@@ -22,10 +22,10 @@ def attr_accessor_with_default(sym, default = nil, &block)
22 22
     raise 'Default value or block required' unless !default.nil? || block
23 23
     define_method(sym, block_given? ? block : Proc.new { default })
24 24
     module_eval(<<-EVAL, __FILE__, __LINE__)
25  
-      def #{sym}=(value)
26  
-        class << self; attr_reader :#{sym} end
27  
-        @#{sym} = value
28  
-      end
  25
+      def #{sym}=(value)                        # def age=(value)
  26
+        class << self; attr_reader :#{sym} end  #   class << self; attr_reader :age end
  27
+        @#{sym} = value                         #   @age = value
  28
+      end                                       # end
29 29
     EVAL
30 30
   end
31 31
 end
48  activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
@@ -15,17 +15,17 @@ def mattr_reader(*syms)
15 15
     syms.each do |sym|
16 16
       next if sym.is_a?(Hash)
17 17
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
18  
-        unless defined? @@#{sym} # unless defined? @@property
19  
-          @@#{sym} = nil         #   @@ property = nil
20  
-        end                      # end
21  
-        
22  
-        def self.#{sym}          # def self.property
23  
-          @@#{sym}               #   @@property
24  
-        end                      # end
25  
-
26  
-        def #{sym}               # def property
27  
-          @@#{sym}               #   @@property
28  
-        end                      # end
  18
+        unless defined? @@#{sym}  # unless defined? @@pagination_options
  19
+          @@#{sym} = nil          #   @@pagination_options = nil
  20
+        end                       # end
  21
+                                  #
  22
+        def self.#{sym}           # def self.pagination_options
  23
+          @@#{sym}                #   @@pagination_options
  24
+        end                       # end
  25
+                                  #
  26
+        def #{sym}                # def pagination_options
  27
+          @@#{sym}                #   @@pagination_options
  28
+        end                       # end
29 29
       EOS
30 30
     end
31 31
   end
@@ -34,19 +34,19 @@ def mattr_writer(*syms)
34 34
     options = syms.extract_options!
35 35
     syms.each do |sym|
36 36
       class_eval(<<-EOS, __FILE__, __LINE__ + 1)
37  
-        unless defined? @@#{sym} # unless defined? @@property
38  
-          @@#{sym} = nil         #   @@ property = nil
39  
-        end                      # end
40  
-                                 
41  
-        def self.#{sym}=(obj)    # def self.property=(obj)
42  
-          @@#{sym} = obj         #   @@property = obj
43  
-        end                      # end
44  
-                                 
45  
-        #{"                      
46  
-        def #{sym}=(obj)         # def property=(obj)
47  
-          @@#{sym} = obj         #   @@property = obj
48  
-        end                      # end
49  
-        " unless options[:instance_writer] == false }
  37
+        unless defined? @@#{sym}                       # unless defined? @@pagination_options
  38
+          @@#{sym} = nil                               #   @@pagination_options = nil
  39
+        end                                            # end
  40
+                                                       #
  41
+        def self.#{sym}=(obj)                          # def self.pagination_options=(obj)
  42
+          @@#{sym} = obj                               #   @@pagination_options = obj
  43
+        end                                            # end
  44
+                                                       #
  45
+        #{"                                            #
  46
+        def #{sym}=(obj)                               # def pagination_options=(obj)
  47
+          @@#{sym} = obj                               #   @@pagination_options = obj
  48
+        end                                            # end
  49
+        " unless options[:instance_writer] == false }  # # instance writer above is generated unless options[:instance_writer] == false
50 50
       EOS
51 51
     end
52 52
   end
6  activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -112,9 +112,9 @@ def delegate(*methods)
112 112
 
113 113
     methods.each do |method|
114 114
       module_eval(<<-EOS, "(__DELEGATION__)", 1)
115  
-        def #{prefix}#{method}(*args, &block)
116  
-          #{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block)
117  
-        end
  115
+        def #{prefix}#{method}(*args, &block)                           # def customer_name(*args, &block)
  116
+          #{allow_nil}#{to}.__send__(#{method.inspect}, *args, &block)  #   client && client.__send__(:name, *args, &block)
  117
+        end                                                             # end
118 118
       EOS
119 119
     end
120 120
   end
10  activesupport/lib/active_support/core_ext/module/synchronization.rb
@@ -26,11 +26,11 @@ def synchronize(*methods)
26 26
       end
27 27
 
28 28
       module_eval(<<-EOS, __FILE__, __LINE__)
29  
-        def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)
30  
-          #{with}.synchronize do
31  
-            #{aliased_method}_without_synchronization#{punctuation}(*args, &block)
32  
-          end
33  
-        end
  29
+        def #{aliased_method}_with_synchronization#{punctuation}(*args, &block)     # def expire_with_synchronization(*args, &block)
  30
+          #{with}.synchronize do                                                    #   @@lock.synchronize do
  31
+            #{aliased_method}_without_synchronization#{punctuation}(*args, &block)  #     expire_without_synchronization(*args, &block)
  32
+          end                                                                       #   end
  33
+        end                                                                         # end
34 34
       EOS
35 35
 
36 36
       alias_method_chain method, :synchronization
15  activesupport/lib/active_support/deprecation.rb
@@ -90,12 +90,15 @@ def deprecate(*method_names)
90 90
         method_names.each do |method_name|
91 91
           alias_method_chain(method_name, :deprecation) do |target, punctuation|
92 92
             class_eval(<<-EOS, __FILE__, __LINE__ + 1)
93  
-              def #{target}_with_deprecation#{punctuation}(*args, &block)                                 # def multi_with_reprecation(*args, &block)
94  
-                ::ActiveSupport::Deprecation.warn(                                                        #   ::ActiveSupport::Deprecation.warn(
95  
-                  self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), #     self.class.deprecated_method_warning(:multi, "this method is deprecated, blah, blah, blah")
96  
-                caller)                                                                                   #   caller)
97  
-                #{target}_without_deprecation#{punctuation}(*args, &block)                                #   multi_without_deprecation(*args, &block)
98  
-              end                                                                                         # end
  93
+              def #{target}_with_deprecation#{punctuation}(*args, &block)   # def generate_secret_with_deprecation(*args, &block)
  94
+                ::ActiveSupport::Deprecation.warn(                          #   ::ActiveSupport::Deprecation.warn(
  95
+                  self.class.deprecated_method_warning(                     #     self.class.deprecated_method_warning(
  96
+                    :#{method_name},                                        #       :generate_secret,
  97
+                    #{options[method_name].inspect}),                       #       "You should use ActiveSupport::SecureRandom.hex(64)"),
  98
+                  caller                                                    #     caller
  99
+                )                                                           #   )
  100
+                #{target}_without_deprecation#{punctuation}(*args, &block)  #   generate_secret_without_deprecation(*args, &block)
  101
+              end                                                           # end
99