Sha256: b73556ea53cdad53e7f6e15968582f56da325a5aa1af3cd7ab8736691ab534df

Contents?: true

Size: 907 Bytes

Versions: 18

Compression:

Stored size: 907 Bytes

Contents

module JSONAPIonify::Api
  module Resource::Builders
    class CursorBuilder < BaseBuilder

      attr_reader :context, :instance
      delegate :type, to: :resource, prefix: true
      delegate :sort_fields_from_sort_string, to: :resource
      delegate :request, :params, to: :context

      def initialize(resource, instance:, context:)
        super(resource)
        @instance = instance
        @context  = context
      end

      def build
        sort_string        = params['sort']
        sort_fields        = sort_fields_from_sort_string(sort_string)
        attrs_with_values  = sort_fields.each_with_object({}) do |field, hash|
          hash[field.name] = instance.send(field.name)
        end
        Base64.urlsafe_encode64(JSON.dump(
          {
            t: resource_type,
            s: sort_string,
            a: attrs_with_values
          }
        ))
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
jsonapionify-0.12.10 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.9 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.8 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.7 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.5 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.4 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.3 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.2 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.1 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.12.0 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.11 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.10 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.9 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.8 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.7 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.6 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.5 lib/jsonapionify/api/resource/builders/cursor_builder.rb
jsonapionify-0.11.0 lib/jsonapionify/api/resource/builders/cursor_builder.rb