Sha256: e425bd365ddfa4700e951f5bb65c8799634a277ce7c7c5fed53a3335e7ed51cc

Contents?: true

Size: 1.69 KB

Versions: 12

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

require 'easy/jsonapi/request/query_param_collection/query_param'

module JSONAPI
  class Request
    class QueryParamCollection < JSONAPI::NameValuePairCollection
      # Used to create a unique Page JSONAPI::Request::QueryParamCollection::QueryParam
      class PageParam < QueryParam
        
        # @param offset [Integer | String] the page offset
        # @param limit [Integer | String] the # of resources returned on a given page
        def initialize(offset:, limit:)
          super('page', { offset: offset.to_i, limit: limit.to_i })
        end

        # @raise [RuntimeError] Informs user to use a different method
        def value
          raise 'PageParam does not provide a #value method, try #offset or #limit instead'
        end

        # @raise [RuntimeError] Informs user to use a different method
        def value=(_)
          raise 'PageParam does not provide a #value= method, try #offset= or #limit= instead'
        end

        # @return [Integer] The page offset
        def offset
          @item[:value][:offset]
        end
  
        # @param new_offset [Integer | String] The new page offset number
        def offset=(new_offset)
          @item[:value][:offset] = new_offset.to_i
        end
  
        # @return [Integer] The # of resources returned on a given page
        def limit
          @item[:value][:limit]
        end
  
        # @param new_limit [Integer] The new page limit number
        def limit=(new_limit)
          @item[:value][:limit] = new_limit.to_i
        end
  
        # Represents the Page class in a string format
        def to_s
          "page[offset]=#{offset}&page[limit]=#{limit}"
        end

      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
easy-jsonapi-1.0.11 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.10 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.9 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.8 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.7 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.6 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.5 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.4 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.3 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.2 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.1 lib/easy/jsonapi/request/query_param_collection/page_param.rb
easy-jsonapi-1.0.0 lib/easy/jsonapi/request/query_param_collection/page_param.rb