Sha256: eeb02894a5f5f9712a5f5ef7ec3eef5badc9591c94f9844688f85d0eb95207c0

Contents?: true

Size: 792 Bytes

Versions: 2

Compression:

Stored size: 792 Bytes

Contents

module JSONAPIonify::Api
  module Resource::Defaults::ResponseContexts
    extend ActiveSupport::Concern

    included do

      # Response Objects
      context(:links, readonly: true) do |context|
        context.response_object[:links]
      end

      context(:meta, readonly: true) do |context|
        JSONAPIonify::Structure::Helpers::MetaDelegate.new context.response_object
      end

      context(:response_object) do |context|
        JSONAPIonify.parse(links: { self: context.request.url })
      end

      context(:response_collection) do |context|
        collections = %i{
            paginated_collection
            sorted_collection
            collection
          }
        context.public_send collections.find { |c| context.respond_to? c }
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jsonapionify-0.9.0 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.0.1.pre lib/jsonapionify/api/resource/defaults/response_contexts.rb