Sha256: 8558086aeda277a8cea7f0812d184fece2dffcddcf68d85245af93480035c9ee
Contents?: true
Size: 1.15 KB
Versions: 9
Compression:
Stored size: 1.15 KB
Contents
module BadgevilleBerlin # Subclasses ActiveResource::Errors to be used by BaseResource as BadgevilleBerlin::Errors. class Errors < ActiveResource::Errors # Grabs errors from the :badgeville_berlin_json response remote model # originating from teh remote class. The custom JSON error response # format may not have a root key :errors. # # @param [String] json the JSON response data in custom # BadgevilleBerlinJsonFormat # @param [Object] save_cache flag that directs the errors cache to be # cleared by default def from_badgeville_berlin_json(json, save_cache = false) formatted_json_decoded = Array.new json_decoded = (ActiveSupport::JSON.decode(json))['errors'] || ActiveSupport::JSON.decode(json) rescue [] json_decoded.each do |attribute_name, err_msgs| if err_msgs.is_a? Array err_msgs.each do |err_msg| formatted_json_decoded.push(attribute_name.humanize + " #{err_msg}") end elsif err_msgs.is_a? String formatted_json_decoded.push(attribute_name, err_msgs) end end from_array formatted_json_decoded, save_cache end end end
Version data entries
9 entries across 9 versions & 1 rubygems