Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11109: no_named_block_arguments_in_associations.patch

File no_named_block_arguments_in_associations.patch, 4.7 kB (added by adymo, 8 months ago)
  • activerecord/lib/active_record/associations/association_proxy.rb

    old new  
    7777        @target.inspect 
    7878      end 
    7979 
     80      def to_xml(options={}, &block) 
     81        if load_target 
     82          @target.to_xml(options, &block) 
     83        end 
     84      end 
     85 
    8086      protected 
    8187        def dependent? 
    8288          @reflection.options[:dependent] 
     
    120126        end 
    121127 
    122128      private 
    123         def method_missing(method, *args, &block
     129        def method_missing(method, *args
    124130          if load_target 
    125             @target.send(method, *args, &block) 
     131            @target.send(method, *args)  { |*block_args| yield(*block_args) if block_given? } 
    126132          end 
    127133        end 
    128134 
  • activerecord/lib/active_record/associations/association_collection.rb

    old new  
    4343      end 
    4444 
    4545      # Calculate sum using SQL, not Enumerable 
    46       def sum(*args, &block
    47         calculate(:sum, *args, &block) 
     46      def sum(*args
     47        calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } 
    4848      end 
    4949 
    5050      # Remove +records+ from this association.  Does not destroy +records+. 
     
    121121        size.zero? 
    122122      end 
    123123 
    124       def any?(&block) 
     124      def any? 
    125125        if block_given? 
    126           method_missing(:any?, &block) 
     126          method_missing(:any?) { |*block_args| yield(*block_args) if block_given? } 
    127127        else 
    128128          !empty? 
    129129        end 
     
    157157 
    158158 
    159159      protected 
    160         def method_missing(method, *args, &block
     160        def method_missing(method, *args
    161161          if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) 
    162             super 
     162            super { |*block_args| yield(*block_args) if block_given? } 
    163163          else 
    164             @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } 
     164            @reflection.klass.send(:with_scope, construct_scope) { 
     165                @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } 
     166            } 
    165167          end 
    166168        end 
    167169 
     
    187189 
    188190      private 
    189191 
    190         def create_record(attrs, &block
     192        def create_record(attrs
    191193          ensure_owner_is_not_new 
    192194          record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) } 
    193           add_record_to_target_with_callbacks(record, &block) 
     195          add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } 
    194196        end 
    195197 
    196         def build_record(attrs, &block
     198        def build_record(attrs
    197199          record = @reflection.klass.new(attrs) 
    198           add_record_to_target_with_callbacks(record, &block) 
     200          add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } 
    199201        end 
    200202 
    201203        def add_record_to_target_with_callbacks(record) 
  • activerecord/lib/active_record/associations/has_many_through_association.rb

    old new  
    113113      end 
    114114 
    115115      # Calculate sum using SQL, not Enumerable 
    116       def sum(*args, &block
    117         calculate(:sum, *args, &block) 
     116      def sum(*args
     117        calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } 
    118118      end 
    119119       
    120120      def count(*args) 
     
    128128      end 
    129129 
    130130      protected 
    131         def method_missing(method, *args, &block
     131        def method_missing(method, *args
    132132          if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) 
    133             super 
     133            super { |*block_args| yield(*block_args) if block_given? } 
    134134          else 
    135             @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } 
     135            @reflection.klass.send(:with_scope, construct_scope) { 
     136                @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } 
     137            } 
    136138          end 
    137139        end 
    138140