Class: OldApiResource::Errors

Inherits:
ActiveModel::Errors
  • Object
show all
Defined in:
lib/old_api_resource/model_errors.rb

Instance Method Summary collapse

Instance Method Details

#from_array(messages, save_cache = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/old_api_resource/model_errors.rb', line 5

def from_array(messages, save_cache = false)
  clear unless save_cache
  humanized_attributes = @base.attributes.keys.inject({}) { |h, attr_name| h.update(attr_name.humanize => attr_name) }
  messages.each do |message|
    attr_message = humanized_attributes.keys.detect do |attr_name|
      if message[0,attr_name.size + 1] == "#{attr_name} "
        add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
      end
    end
  end
end

#from_hash(messages, save_cache = false) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/old_api_resource/model_errors.rb', line 17

def from_hash(messages, save_cache = false)
  clear unless save_cache
  messages.each do |attr, message_array|
    message_array.each do |message|
      add attr, message
    end
  end
end