Sha256: 1efc7cc968bedaf6863e3315e9d454f8154f7a3d9cc758f7700933aa7eb6ffd6
Contents?: true
Size: 961 Bytes
Versions: 5
Compression:
Stored size: 961 Bytes
Contents
module AbsorbApi class ResourceNotFound < StandardError; end class RouteNotFound < StandardError; end class ValidationError < StandardError; end module Orm extend ActiveSupport::Concern class_methods do def find(id) raise ResourceNotFound if id.blank? response = AbsorbApi.api.get("#{to_s.demodulize.pluralize}/#{id}") if response.status == 404 raise(RouteNotFound) elsif response.status == 400 raise ResourceNotFound else new(response.body) end end def all response = AbsorbApi.api.get("#{to_s.demodulize.pluralize}") if response.status == 404 raise RouteNotFound elsif response.status == 400 raise ResourceNotFound else Collection.new( response.body.map! do |attributes| new(attributes) end, {klass: to_s.demodulize } ) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems