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 77 77 @target.inspect 78 78 end 79 79 80 def to_xml(options={}, &block) 81 if load_target 82 @target.to_xml(options, &block) 83 end 84 end 85 80 86 protected 81 87 def dependent? 82 88 @reflection.options[:dependent] … … 120 126 end 121 127 122 128 private 123 def method_missing(method, *args , &block)129 def method_missing(method, *args) 124 130 if load_target 125 @target.send(method, *args , &block)131 @target.send(method, *args) { |*block_args| yield(*block_args) if block_given? } 126 132 end 127 133 end 128 134 -
activerecord/lib/active_record/associations/association_collection.rb
old new 43 43 end 44 44 45 45 # 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? } 48 48 end 49 49 50 50 # Remove +records+ from this association. Does not destroy +records+. … … 121 121 size.zero? 122 122 end 123 123 124 def any? (&block)124 def any? 125 125 if block_given? 126 method_missing(:any? , &block)126 method_missing(:any?) { |*block_args| yield(*block_args) if block_given? } 127 127 else 128 128 !empty? 129 129 end … … 157 157 158 158 159 159 protected 160 def method_missing(method, *args , &block)160 def method_missing(method, *args) 161 161 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? } 163 163 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 } 165 167 end 166 168 end 167 169 … … 187 189 188 190 private 189 191 190 def create_record(attrs , &block)192 def create_record(attrs) 191 193 ensure_owner_is_not_new 192 194 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? } 194 196 end 195 197 196 def build_record(attrs , &block)198 def build_record(attrs) 197 199 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? } 199 201 end 200 202 201 203 def add_record_to_target_with_callbacks(record) -
activerecord/lib/active_record/associations/has_many_through_association.rb
old new 113 113 end 114 114 115 115 # 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? } 118 118 end 119 119 120 120 def count(*args) … … 128 128 end 129 129 130 130 protected 131 def method_missing(method, *args , &block)131 def method_missing(method, *args) 132 132 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? } 134 134 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 } 136 138 end 137 139 end 138 140