Class: ApiResource::Errors
- Inherits:
-
ActiveModel::Errors
- Object
- ActiveModel::Errors
- ApiResource::Errors
- Defined in:
- lib/api_resource/model_errors.rb
Instance Method Summary collapse
- #from_array(messages, save_cache = false) ⇒ Object
- #from_hash(messages, save_cache = false) ⇒ Object
Instance Method Details
#from_array(messages, save_cache = false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/api_resource/model_errors.rb', line 5 def from_array(, save_cache = false) clear unless save_cache humanized_attributes = @base.attributes.keys.inject({}){|h, attr_name| h.update(attr_name.to_s.humanize => attr_name) } .each do || = humanized_attributes.keys.detect do |attr_name| if [0,attr_name.size + 1] == "#{attr_name} " self.add( humanized_attributes[attr_name], [(attr_name.size + 1)..-1] ) end end end end |
#from_hash(messages, save_cache = false) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/api_resource/model_errors.rb', line 22 def from_hash(, save_cache = false) clear unless save_cache .each do |attr, | .each do || self.add(attr, ) end end end |