Sha256: f67d961f33673457d3d7eb8381a80e73556e2467bd41df500a98fbb3edc28047

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 KB

Contents

module JSONAPIonify::Api
  module Resource::Definitions::Scopes

    def scope(&block)
      define_singleton_method(:current_scope) do
        instance_exec(OpenStruct.new, &block)
      end
      context :scope do |context|
        instance_exec(context, &block)
      end
    end

    alias_method :resource_class, :scope

    def instance(&block)
      define_singleton_method(:find_instance) do |id|
        instance_exec(current_scope, id, OpenStruct.new, &block)
      end
      context :instance, persisted: true do |context|
        instance_exec(context.scope, context.id, context, &block)
      end
    end

    def collection(&block)
      context :collection do |context|
        Object.new.instance_exec(context.scope, context, &block)
      end
    end

    def new_instance(&block)
      define_singleton_method(:build_instance) do
        Object.new.instance_exec(current_scope, &block)
      end
      context :new_instance, persisted: true, readonly: true do |context|
        Object.new.instance_exec(context.scope, context, &block)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
jsonapionify-0.11.11 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.11.10 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.11.9 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.11.8 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.11.7 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.11.6 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.11.5 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.11.0 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.10.2 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.10.1 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.10.0 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.9.3 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.9.2 lib/jsonapionify/api/resource/definitions/scopes.rb
jsonapionify-0.9.1 lib/jsonapionify/api/resource/definitions/scopes.rb