Skip to content

Commit b3a74a1

Browse files
committed
Merge pull request rails#10408 from patricksrobertson/convert_activemodel_to_new_hash_syntax
Convert ActiveModel to 1.9 hash syntax.
2 parents dd1f360 + eebb9dd commit b3a74a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+351
-349
lines changed

activemodel/lib/active_model/attribute_methods.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def instance_method_already_implemented?(method_name) #:nodoc:
343343
# significantly (in our case our test suite finishes 10% faster with
344344
# this cache).
345345
def attribute_method_matchers_cache #:nodoc:
346-
@attribute_method_matchers_cache ||= ThreadSafe::Cache.new(:initial_capacity => 4)
346+
@attribute_method_matchers_cache ||= ThreadSafe::Cache.new(initial_capacity: 4)
347347
end
348348

349349
def attribute_method_matcher(method_name) #:nodoc:

activemodel/lib/active_model/callbacks.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ def self.extended(base) #:nodoc:
100100
def define_model_callbacks(*callbacks)
101101
options = callbacks.extract_options!
102102
options = {
103-
:terminator => "result == false",
104-
:skip_after_callbacks_if_terminated => true,
105-
:scope => [:kind, :name],
106-
:only => [:before, :around, :after]
103+
terminator: "result == false",
104+
skip_after_callbacks_if_terminated: true,
105+
scope: [:kind, :name],
106+
only: [:before, :around, :after]
107107
}.merge!(options)
108108

109109
types = Array(options.delete(:only))

activemodel/lib/active_model/dirty.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module Dirty
9191

9292
included do
9393
attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
94-
attribute_method_affix :prefix => 'reset_', :suffix => '!'
94+
attribute_method_affix prefix: 'reset_', suffix: '!'
9595
end
9696

9797
# Returns +true+ if any attribute have unsaved changes, +false+ otherwise.

activemodel/lib/active_model/errors.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def empty?
231231
# # <error>name must be specified</error>
232232
# # </errors>
233233
def to_xml(options={})
234-
to_a.to_xml({ :root => "errors", :skip_types => true }.merge!(options))
234+
to_a.to_xml({ root: "errors", skip_types: true }.merge!(options))
235235
end
236236

237237
# Returns a Hash that can be used as the JSON representation for this
@@ -370,11 +370,11 @@ def full_messages_for(attribute)
370370
def full_message(attribute, message)
371371
return message if attribute == :base
372372
attr_name = attribute.to_s.tr('.', '_').humanize
373-
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
373+
attr_name = @base.class.human_attribute_name(attribute, default: attr_name)
374374
I18n.t(:"errors.format", {
375-
:default => "%{attribute} %{message}",
376-
:attribute => attr_name,
377-
:message => message
375+
default: "%{attribute} %{message}",
376+
attribute: attr_name,
377+
message: message
378378
})
379379
end
380380

@@ -426,10 +426,10 @@ def generate_message(attribute, type = :invalid, options = {})
426426
value = (attribute != :base ? @base.send(:read_attribute_for_validation, attribute) : nil)
427427

428428
options = {
429-
:default => defaults,
430-
:model => @base.class.model_name.human,
431-
:attribute => @base.class.human_attribute_name(attribute),
432-
:value => value
429+
default: defaults,
430+
model: @base.class.model_name.human,
431+
attribute: @base.class.human_attribute_name(attribute),
432+
value: value
433433
}.merge!(options)
434434

435435
I18n.translate(key, options)

activemodel/lib/active_model/naming.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Name
129129
#
130130
# Equivalent to +to_s+.
131131
delegate :==, :===, :<=>, :=~, :"!~", :eql?, :to_s,
132-
:to_str, :to => :name
132+
:to_str, to: :name
133133

134134
# Returns a new ActiveModel::Name instance. By default, the +namespace+
135135
# and +name+ option will take the namespace and name of the given class
@@ -183,7 +183,7 @@ def human(options={})
183183
defaults << options[:default] if options[:default]
184184
defaults << @human
185185

186-
options = { :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults }.merge!(options.except(:default))
186+
options = { scope: [@klass.i18n_scope, :models], count: 1, default: defaults }.merge!(options.except(:default))
187187
I18n.translate(defaults.shift, options)
188188
end
189189

activemodel/lib/active_model/secure_password.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def has_secure_password(options = {})
5757

5858
if options.fetch(:validations, true)
5959
validates_confirmation_of :password
60-
validates_presence_of :password, :on => :create
60+
validates_presence_of :password, on: :create
6161

6262
before_create { raise "Password digest missing on new record" if password_digest.blank? }
6363
end

activemodel/lib/active_model/serializers/xml.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def serialize
7979
require 'builder' unless defined? ::Builder
8080

8181
options[:indent] ||= 2
82-
options[:builder] ||= ::Builder::XmlMarkup.new(:indent => options[:indent])
82+
options[:builder] ||= ::Builder::XmlMarkup.new(indent: options[:indent])
8383

8484
@builder = options[:builder]
8585
@builder.instruct! unless options[:skip_instruct]
@@ -88,8 +88,8 @@ def serialize
8888
root = ActiveSupport::XmlMini.rename_key(root, options)
8989

9090
args = [root]
91-
args << {:xmlns => options[:namespace]} if options[:namespace]
92-
args << {:type => options[:type]} if options[:type] && !options[:skip_types]
91+
args << { xmlns: options[:namespace] } if options[:namespace]
92+
args << { type: options[:type] } if options[:type] && !options[:skip_types]
9393

9494
@builder.tag!(*args) do
9595
add_attributes_and_methods
@@ -132,7 +132,7 @@ def add_associations(association, records, opts)
132132
records = records.to_ary
133133

134134
tag = ActiveSupport::XmlMini.rename_key(association.to_s, options)
135-
type = options[:skip_types] ? { } : {:type => "array"}
135+
type = options[:skip_types] ? { } : { type: "array" }
136136
association_name = association.to_s.singularize
137137
merged_options[:root] = association_name
138138

@@ -145,7 +145,7 @@ def add_associations(association, records, opts)
145145
record_type = {}
146146
else
147147
record_class = (record.class.to_s.underscore == association_name) ? nil : record.class.name
148-
record_type = {:type => record_class}
148+
record_type = { type: record_class }
149149
end
150150

151151
record.to_xml merged_options.merge(record_type)

activemodel/lib/active_model/translation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def lookup_ancestors
4141
#
4242
# Specify +options+ with additional translating options.
4343
def human_attribute_name(attribute, options = {})
44-
options = { :count => 1 }.merge!(options)
44+
options = { count: 1 }.merge!(options)
4545
parts = attribute.to_s.split(".")
4646
attribute = parts.pop
4747
namespace = parts.join("/") unless parts.empty?

activemodel/lib/active_model/validations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module Validations
4646
include HelperMethods
4747

4848
attr_accessor :validation_context
49-
define_callbacks :validate, :scope => :name
49+
define_callbacks :validate, scope: :name
5050

5151
class_attribute :_validators
5252
self._validators = Hash.new { |h,k| h[k] = [] }

activemodel/lib/active_model/validations/acceptance.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module ActiveModel
33
module Validations
44
class AcceptanceValidator < EachValidator # :nodoc:
55
def initialize(options)
6-
super({ :allow_nil => true, :accept => "1" }.merge!(options))
6+
super({ allow_nil: true, accept: "1" }.merge!(options))
77
end
88

99
def validate_each(record, attribute, value)

0 commit comments

Comments
 (0)