aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/conversions.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 17:58:50 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:10:53 +0200
commitd66e7835bea9505f7003e5038aa19b6ea95ceea1 (patch)
tree9846f86c6d130595f54c389c83b66d57101563c5 /activesupport/lib/active_support/core_ext/hash/conversions.rb
parent77eb40dab64e1fe2a759044d4f122dc0ef833141 (diff)
downloadrails-d66e7835bea9505f7003e5038aa19b6ea95ceea1.tar.gz
rails-d66e7835bea9505f7003e5038aa19b6ea95ceea1.tar.bz2
rails-d66e7835bea9505f7003e5038aa19b6ea95ceea1.zip
applies new string literal convention in activesupport/lib
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb46
1 files changed, 23 insertions, 23 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 2fc514cfce..a4396be4ad 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -1,11 +1,11 @@
-require 'active_support/xml_mini'
-require 'active_support/time'
-require 'active_support/core_ext/object/blank'
-require 'active_support/core_ext/object/to_param'
-require 'active_support/core_ext/object/to_query'
-require 'active_support/core_ext/array/wrap'
-require 'active_support/core_ext/hash/reverse_merge'
-require 'active_support/core_ext/string/inflections'
+require "active_support/xml_mini"
+require "active_support/time"
+require "active_support/core_ext/object/blank"
+require "active_support/core_ext/object/to_param"
+require "active_support/core_ext/object/to_query"
+require "active_support/core_ext/array/wrap"
+require "active_support/core_ext/hash/reverse_merge"
+require "active_support/core_ext/string/inflections"
class Hash
# Returns a string containing an XML representation of its receiver:
@@ -71,11 +71,11 @@ class Hash
# configure your own builder with the <tt>:builder</tt> option. The method also accepts
# options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.
def to_xml(options = {})
- require 'active_support/builder' unless defined?(Builder)
+ require "active_support/builder" unless defined?(Builder)
options = options.dup
options[:indent] ||= 2
- options[:root] ||= 'hash'
+ options[:root] ||= "hash"
options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
builder = options[:builder]
@@ -160,7 +160,7 @@ module ActiveSupport
def normalize_keys(params)
case params
when Hash
- Hash[params.map { |k,v| [k.to_s.tr('-', '_'), normalize_keys(v)] } ]
+ Hash[params.map { |k,v| [k.to_s.tr("-", "_"), normalize_keys(v)] } ]
when Array
params.map { |v| normalize_keys(v) }
else
@@ -182,13 +182,13 @@ module ActiveSupport
end
def process_hash(value)
- if value.include?('type') && !value['type'].is_a?(Hash) && @disallowed_types.include?(value['type'])
- raise DisallowedType, value['type']
+ if value.include?("type") && !value["type"].is_a?(Hash) && @disallowed_types.include?(value["type"])
+ raise DisallowedType, value["type"]
end
if become_array?(value)
_, entries = Array.wrap(value.detect { |k,v| not v.is_a?(String) })
- if entries.nil? || value['__content__'].try(:empty?)
+ if entries.nil? || value["__content__"].try(:empty?)
[]
else
case entries
@@ -204,28 +204,28 @@ module ActiveSupport
process_content(value)
elsif become_empty_string?(value)
- ''
+ ""
elsif become_hash?(value)
xml_value = Hash[value.map { |k,v| [k, deep_to_h(v)] }]
# Turn { files: { file: #<StringIO> } } into { files: #<StringIO> } so it is compatible with
# how multipart uploaded files from HTML appear
- xml_value['file'].is_a?(StringIO) ? xml_value['file'] : xml_value
+ xml_value["file"].is_a?(StringIO) ? xml_value["file"] : xml_value
end
end
def become_content?(value)
- value['type'] == 'file' || (value['__content__'] && (value.keys.size == 1 || value['__content__'].present?))
+ value["type"] == "file" || (value["__content__"] && (value.keys.size == 1 || value["__content__"].present?))
end
def become_array?(value)
- value['type'] == 'array'
+ value["type"] == "array"
end
def become_empty_string?(value)
# { "string" => true }
# No tests fail when the second term is removed.
- value['type'] == 'string' && value['nil'] != 'true'
+ value["type"] == "string" && value["nil"] != "true"
end
def become_hash?(value)
@@ -234,19 +234,19 @@ module ActiveSupport
def nothing?(value)
# blank or nil parsed values are represented by nil
- value.blank? || value['nil'] == 'true'
+ value.blank? || value["nil"] == "true"
end
def garbage?(value)
# If the type is the only element which makes it then
# this still makes the value nil, except if type is
# an XML node(where type['value'] is a Hash)
- value['type'] && !value['type'].is_a?(::Hash) && value.size == 1
+ value["type"] && !value["type"].is_a?(::Hash) && value.size == 1
end
def process_content(value)
- content = value['__content__']
- if parser = ActiveSupport::XmlMini::PARSING[value['type']]
+ content = value["__content__"]
+ if parser = ActiveSupport::XmlMini::PARSING[value["type"]]
parser.arity == 1 ? parser.call(content) : parser.call(content, value)
else
content