aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/nested_attributes.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 18:24:04 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:26:45 +0200
commit4df2b779ddfcb27761c71e00e2b241bfa06a0950 (patch)
tree7a83cce62195f7b20afea6d6a8873b953d25cb84 /activerecord/lib/active_record/nested_attributes.rb
parenta731125f12c5834de7eae3455fad63ea4d348034 (diff)
downloadrails-4df2b779ddfcb27761c71e00e2b241bfa06a0950.tar.gz
rails-4df2b779ddfcb27761c71e00e2b241bfa06a0950.tar.bz2
rails-4df2b779ddfcb27761c71e00e2b241bfa06a0950.zip
applies new string literal convention in activerecord/lib
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'activerecord/lib/active_record/nested_attributes.rb')
-rw-r--r--activerecord/lib/active_record/nested_attributes.rb32
1 files changed, 16 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb
index fe68869143..819e181f61 100644
--- a/activerecord/lib/active_record/nested_attributes.rb
+++ b/activerecord/lib/active_record/nested_attributes.rb
@@ -1,6 +1,6 @@
-require 'active_support/core_ext/hash/except'
-require 'active_support/core_ext/object/try'
-require 'active_support/core_ext/hash/indifferent_access'
+require "active_support/core_ext/hash/except"
+require "active_support/core_ext/object/try"
+require "active_support/core_ext/hash/indifferent_access"
module ActiveRecord
module NestedAttributes #:nodoc:
@@ -267,7 +267,7 @@ module ActiveRecord
# member.avatar_attributes = {icon: 'sad'}
# member.avatar.width # => 200
module ClassMethods
- REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |key, value| key == '_destroy' || value.blank? } }
+ REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |key, value| key == "_destroy" || value.blank? } }
# Defines an attributes writer for the specified association(s).
#
@@ -400,12 +400,12 @@ module ActiveRecord
attributes = attributes.with_indifferent_access
existing_record = send(association_name)
- if (options[:update_only] || !attributes['id'].blank?) && existing_record &&
- (options[:update_only] || existing_record.id.to_s == attributes['id'].to_s)
+ if (options[:update_only] || !attributes["id"].blank?) && existing_record &&
+ (options[:update_only] || existing_record.id.to_s == attributes["id"].to_s)
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy]) unless call_reject_if(association_name, attributes)
- elsif attributes['id'].present?
- raise_nested_attributes_record_not_found!(association_name, attributes['id'])
+ elsif attributes["id"].present?
+ raise_nested_attributes_record_not_found!(association_name, attributes["id"])
elsif !reject_new_record?(association_name, attributes)
assignable_attributes = attributes.except(*UNASSIGNABLE_KEYS)
@@ -465,7 +465,7 @@ module ActiveRecord
if attributes_collection.is_a? Hash
keys = attributes_collection.keys
- attributes_collection = if keys.include?('id') || keys.include?(:id)
+ attributes_collection = if keys.include?("id") || keys.include?(:id)
[attributes_collection]
else
attributes_collection.values
@@ -477,7 +477,7 @@ module ActiveRecord
existing_records = if association.loaded?
association.target
else
- attribute_ids = attributes_collection.map {|a| a['id'] || a[:id] }.compact
+ attribute_ids = attributes_collection.map {|a| a["id"] || a[:id] }.compact
attribute_ids.empty? ? [] : association.scope.where(association.klass.primary_key => attribute_ids)
end
@@ -487,16 +487,16 @@ module ActiveRecord
end
attributes = attributes.with_indifferent_access
- if attributes['id'].blank?
+ if attributes["id"].blank?
unless reject_new_record?(association_name, attributes)
association.build(attributes.except(*UNASSIGNABLE_KEYS))
end
- elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes['id'].to_s }
+ elsif existing_record = existing_records.detect { |record| record.id.to_s == attributes["id"].to_s }
unless call_reject_if(association_name, attributes)
# Make sure we are operating on the actual object which is in the association's
# proxy_target array (either by finding it, or adding it if not found)
# Take into account that the proxy_target may have changed due to callbacks
- target_record = association.target.detect { |record| record.id.to_s == attributes['id'].to_s }
+ target_record = association.target.detect { |record| record.id.to_s == attributes["id"].to_s }
if target_record
existing_record = target_record
else
@@ -506,7 +506,7 @@ module ActiveRecord
assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
end
else
- raise_nested_attributes_record_not_found!(association_name, attributes['id'])
+ raise_nested_attributes_record_not_found!(association_name, attributes["id"])
end
end
end
@@ -543,7 +543,7 @@ module ActiveRecord
# Determines if a hash contains a truthy _destroy key.
def has_destroy_flag?(hash)
- Type::Boolean.new.cast(hash['_destroy'])
+ Type::Boolean.new.cast(hash["_destroy"])
end
# Determines if a new record should be rejected by checking
@@ -581,7 +581,7 @@ module ActiveRecord
def raise_nested_attributes_record_not_found!(association_name, record_id)
model = self.class._reflect_on_association(association_name).klass.name
raise RecordNotFound.new("Couldn't find #{model} with ID=#{record_id} for #{self.class.name} with ID=#{id}",
- model, 'id', record_id)
+ model, "id", record_id)
end
end
end