Class: ActiveResource::Errors
- Inherits:
-
ActiveModel::Errors
- Object
- ActiveModel::Errors
- ActiveResource::Errors
- Defined in:
- activeresource/lib/active_resource/validations.rb
Overview
Active Resource validation is reported to and from this object, which is used by Base#save to determine whether the object in a valid state to be saved. See usage example in Validations.
Constant Summary
Constants inherited from ActiveModel::Errors
ActiveModel::Errors::CALLBACKS_OPTIONS
Instance Attribute Summary
Attributes inherited from ActiveModel::Errors
Instance Method Summary collapse
-
#from_array(messages, save_cache = false) ⇒ Object
Grabs errors from an array of messages (like ActiveRecord::Validations).
-
#from_json(json, save_cache = false) ⇒ Object
Grabs errors from a json response.
-
#from_xml(xml, save_cache = false) ⇒ Object
Grabs errors from an XML response.
Methods inherited from ActiveModel::Errors
#[], #[]=, #add, #add_on_blank, #add_on_empty, #added?, #as_json, #clear, #count, #delete, #dup, #each, #empty?, #full_message, #full_messages, #generate_message, #get, #include?, #initialize, #initialize_dup, #keys, #set, #size, #to_a, #to_hash, #to_xml, #values
Methods included from Enumerable
#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum
Constructor Details
This class inherits a constructor from ActiveModel::Errors
Instance Method Details
#from_array(messages, save_cache = false) ⇒ Object
Grabs errors from an array of messages (like ActiveRecord::Validations). The second parameter directs the errors cache to be cleared (default) or not (by passing true).
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'activeresource/lib/active_resource/validations.rb', line 14 def from_array(, save_cache = false) clear unless save_cache humanized_attributes = Hash[@base.attributes.keys.map { |attr_name| [attr_name.humanize, attr_name] }] .each do || = humanized_attributes.keys.detect do |attr_name| if [0, attr_name.size + 1] == "#{attr_name} " add humanized_attributes[attr_name], [(attr_name.size + 1)..-1] end end self[:base] << if .nil? end end |
#from_json(json, save_cache = false) ⇒ Object
Grabs errors from a json response.
29 30 31 32 |
# File 'activeresource/lib/active_resource/validations.rb', line 29 def from_json(json, save_cache = false) array = Array.wrap(ActiveSupport::JSON.decode(json)['errors']) rescue [] from_array array, save_cache end |