Class: ActiveResource::Errors

Inherits:
ActiveModel::Errors
  • Object
show all
Defined in:
lib/mite/activeresource_patch.rb

Instance Method Summary collapse

Instance Method Details

#from_hash(messages, save_cache = false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mite/activeresource_patch.rb', line 10

def from_hash(messages, save_cache = false)
  clear unless save_cache

  messages.each do |(key,errors)|
    Array(errors).each do |error|
      if key == 'base'
        self[:base] << error
      else
        add key, error
      end
    end
  end
end

#from_json(json, save_cache = false) ⇒ Object



5
6
7
8
# File 'lib/mite/activeresource_patch.rb', line 5

def from_json(json, save_cache = false)
  decoded = ActiveSupport::JSON.decode(json) || {} rescue {}
  from_hash decoded, save_cache
end