Skip to content

Commit

Permalink
Removed unnecessary call to #try and cleaned up a bit more.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Jan 7, 2010
1 parent 4b7a439 commit 3d17d79
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions activerecord/lib/active_record/nested_attributes.rb
Expand Up @@ -287,7 +287,7 @@ def _delete #:nodoc:
# update_only is true, and a <tt>:_destroy</tt> key set to a truthy value, # update_only is true, and a <tt>:_destroy</tt> key set to a truthy value,
# then the existing record will be marked for destruction. # then the existing record will be marked for destruction.
def assign_nested_attributes_for_one_to_one_association(association_name, attributes) def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
options = self.nested_attributes_options[association_name] options = nested_attributes_options[association_name]
attributes = attributes.with_indifferent_access attributes = attributes.with_indifferent_access
check_existing_record = (options[:update_only] || !attributes['id'].blank?) check_existing_record = (options[:update_only] || !attributes['id'].blank?)


Expand Down Expand Up @@ -332,7 +332,7 @@ def assign_nested_attributes_for_one_to_one_association(association_name, attrib
# { :id => '2', :_destroy => true } # { :id => '2', :_destroy => true }
# ]) # ])
def assign_nested_attributes_for_collection_association(association_name, attributes_collection) def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
options = self.nested_attributes_options[association_name] options = nested_attributes_options[association_name]


unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array) unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})" raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
Expand Down Expand Up @@ -383,13 +383,11 @@ def reject_new_record?(association_name, attributes)
end end


def call_reject_if(association_name, attributes) def call_reject_if(association_name, attributes)
callback = self.nested_attributes_options[association_name][:reject_if] case callback = nested_attributes_options[association_name][:reject_if]

case callback
when Symbol when Symbol
method(callback).arity == 0 ? send(callback) : send(callback, attributes) method(callback).arity == 0 ? send(callback) : send(callback, attributes)
when Proc when Proc
callback.try(:call, attributes) callback.call(attributes)
end end
end end
end end
Expand Down

0 comments on commit 3d17d79

Please sign in to comment.