Sha256: ceb77dc7923934367eaa80d663b1861f1e89d06053aa5eef8c98df4eca175f5e

Contents?: true

Size: 954 Bytes

Versions: 8

Compression:

Stored size: 954 Bytes

Contents

module JSONAPIonify::Api
  module Resource::Defaults::Options
    def self.scope_is_active_record? scope
      return false unless defined?(ActiveRecord)
      scope < ActiveRecord::Base
    rescue NoMethodError, ArgumentError, TypeError
      false
    end

    extend ActiveSupport::Concern
    included do
      id :id
      scope { self.type.classify.constantize }
      collection do |scope|
        Resource::Defaults::Options.scope_is_active_record?(scope) ? scope.all : scope
      end

      instance do |scope, key|
        raise NotImplementedError, 'instance not implemented' unless Resource::Defaults::Options.scope_is_active_record?(scope)
        scope.find_by! id_attribute => key
      end

      new_instance do |scope|
        raise NotImplementedError, 'new_instance not implemented' unless scope.respond_to?(:new)
        scope.new
      end

      # Invoke validating contexts
      before { |request_headers:| }

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
jsonapionify-0.12.8 lib/jsonapionify/api/resource/defaults/options.rb
jsonapionify-0.12.7 lib/jsonapionify/api/resource/defaults/options.rb
jsonapionify-0.12.5 lib/jsonapionify/api/resource/defaults/options.rb
jsonapionify-0.12.4 lib/jsonapionify/api/resource/defaults/options.rb
jsonapionify-0.12.3 lib/jsonapionify/api/resource/defaults/options.rb
jsonapionify-0.12.2 lib/jsonapionify/api/resource/defaults/options.rb
jsonapionify-0.12.1 lib/jsonapionify/api/resource/defaults/options.rb
jsonapionify-0.12.0 lib/jsonapionify/api/resource/defaults/options.rb