Sha256: 7efe3d1da3b2875af309a8f550132434a13842e5f766a9ad12219238275c534f

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

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

    included do
      context(:invalidate_cache?, readonly: true, persisted: true) { |c| c.includes.present? }

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

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

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

      context(:response_collection, readonly: true) do |context|
        if context.root_request?
          collections = %i{
            paginated_collection
            sorted_collection
            collection
          }
          context.public_send collections.find { |c| context.respond_to? c }
        else
          context.collection
        end
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jsonapionify-0.11.11 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.11.10 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.11.9 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.11.8 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.11.7 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.11.6 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.11.5 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.11.0 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.10.2 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.10.1 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.10.0 lib/jsonapionify/api/resource/defaults/response_contexts.rb
jsonapionify-0.9.3 lib/jsonapionify/api/resource/defaults/response_contexts.rb