Sha256: abf6717e23f22eb074fd0400c7ff8bf68ce4f5322d7bf7b903472ff474e5e375

Contents?: true

Size: 770 Bytes

Versions: 4

Compression:

Stored size: 770 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 = Base.api.get("#{to_s.demodulize.pluralize}/#{id}")
        response.status == 404 ? raise(ResourceNotFound) : new(response.body)
      end

      def all
        response = Base.api.get("#{to_s.demodulize.pluralize}")
        if response.status == 404
          raise RouteNotFound
        else
          Collection.new( response.body.map! do |attributes|
            new(attributes)
          end, {klass: to_s.demodulize } )
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
absorb_api-0.1.5 lib/absorb_api/orm.rb
absorb_api-0.1.2 lib/absorb_api/orm.rb
absorb_api-0.1.1 lib/absorb_api/orm.rb
absorb_api-0.1.0 lib/absorb_api/orm.rb