Sha256: 2fd45639ffd5131d1c60071b09348a660c7cb019e3090d8bf3860701ab880e74
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
module GraphitiSpecHelpers class ErrorsProxy class Error attr_reader :json def initialize(json) @json = json end def attribute @json[:meta][:attribute] end # TODO: move to top-level code in errorable def code @json[:meta][:code] end def message @json[:meta][:message] end def title @json[:title] end def detail @json[:detail] end def status @json[:status] end end include Enumerable def initialize(array) @errors = array.map { |e| Error.new(e) } end def [](key) @errors[key] end def each(&blk) @errors.each(&blk) end def length count end def to_h {}.tap do |hash| @errors.each do |e| hash[e.attribute] = e.message end end end def method_missing(id, *args, &blk) if error = @errors.find { |e| e.attribute == id } return error else super end end end end
Version data entries
3 entries across 3 versions & 1 rubygems