Class: ActiveResource::Errors

Inherits:
ActiveModel::Errors
  • Object
show all
Defined in:
lib/active_resource/json_errors.rb

Instance Method Summary collapse

Instance Method Details

#from_hash(messages, save_cache = false) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/active_resource/json_errors.rb', line 15

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

  messages.each do |key,errors|
    errors.each do |error|
      add(key, error)
    end
  end
end

#from_json(json, save_cache = false) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/active_resource/json_errors.rb', line 5

def from_json(json, save_cache = false)
  data = ActiveSupport::JSON.decode(json)['errors'] || {} rescue {}
  case data
  when String
    from_string(data, save_cache)
  else
    from_hash(data, save_cache)
  end
end

#from_string(error, save_cache = false) ⇒ Object



25
26
27
28
29
# File 'lib/active_resource/json_errors.rb', line 25

def from_string(error, save_cache = false)
  clear unless save_cache

  add("message", error)
end