Sha256: 052df71dc873edc5168ee948d737a53bed9ae1fff1a94ae0c04b57e465417088

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

module JsonapiCompliable
  class Resource
    module Interface
      extend ActiveSupport::Concern

      class_methods do
        def all(params = {}, base_scope = nil)
          _all(params, {}, base_scope)
        end

        def _all(params, opts, base_scope)
          runner = Runner.new(self, params)
          runner.proxy(base_scope, opts)
        end

        def find(params, base_scope = nil)
          id = params[:data].try(:[], :id) || params.delete(:id)
          params[:filter] ||= {}
          params[:filter].merge!(id: id)

          runner = Runner.new(self, params)
          runner.proxy(base_scope, single: true, raise_on_missing: true)
        end

        def build(params, base_scope = nil)
          runner = Runner.new(self, params)
          runner.proxy(base_scope, single: true, raise_on_missing: true)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonapi_compliable-1.0.alpha.2 lib/jsonapi_compliable/resource/interface.rb