diff options
author | José Valim <jose.valim@gmail.com> | 2012-04-28 00:17:18 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-04-28 00:17:18 -0700 |
commit | fc6b115b88eb600a3eefb47484f4e8462c103cbe (patch) | |
tree | ae5a8ac55d885d75b70b4717771d1b5f2970672f /activemodel/lib/active_model | |
parent | d0e1c692b455093ca958a70e2d729b8b17b3f02b (diff) | |
parent | 709b748f095590ea4ab01a37970fa8c1e9a15a40 (diff) | |
download | rails-fc6b115b88eb600a3eefb47484f4e8462c103cbe.tar.gz rails-fc6b115b88eb600a3eefb47484f4e8462c103cbe.tar.bz2 rails-fc6b115b88eb600a3eefb47484f4e8462c103cbe.zip |
Merge pull request #6025 from carlosantoniodasilva/amo-errors-refactor
Refactor AMo::Errors
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 0c628c33c2..aba6618b56 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -3,7 +3,6 @@ require 'active_support/core_ext/array/conversions' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/hash/reverse_merge' module ActiveModel # == Active Model Errors @@ -202,12 +201,12 @@ module ActiveModel # # <error>name must be specified</error> # # </errors> def to_xml(options={}) - to_a.to_xml options.reverse_merge(:root => "errors", :skip_types => true) + to_a.to_xml({ :root => "errors", :skip_types => true }.merge!(options)) end # Returns an Hash that can be used as the JSON representation for this object. # Options: - # * <tt>:full_messages</tt> - determines if json object should contain + # * <tt>:full_messages</tt> - determines if json object should contain # full messages or not. Default: <tt>false</tt>. def as_json(options=nil) to_hash(options && options[:full_messages]) @@ -217,7 +216,7 @@ module ActiveModel if full_messages messages = {} self.messages.each do |attribute, array| - messages[attribute] = array.map{|message| full_message(attribute, message) } + messages[attribute] = array.map { |message| full_message(attribute, message) } end messages else @@ -347,7 +346,7 @@ module ActiveModel :model => @base.class.model_name.human, :attribute => @base.class.human_attribute_name(attribute), :value => value - }.merge(options) + }.merge!(options) I18n.translate(key, options) end @@ -356,9 +355,10 @@ module ActiveModel def normalize_message(attribute, message, options) message ||= :invalid - if message.is_a?(Symbol) + case message + when Symbol generate_message(attribute, message, options.except(*CALLBACKS_OPTIONS)) - elsif message.is_a?(Proc) + when Proc message.call else message |