Sha256: 821051f995754320bf98f94c8a6ed7e8b483e83443f453ff37e3ac2012b9c54a

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require 'easy/jsonapi/name_value_pair_collection'
require 'easy/jsonapi/utility'

module JSONAPI
  class Request
    # A collection of QueryParam objects 
    class QueryParamCollection < JSONAPI::NameValuePairCollection

      # @param param_arr [Array<JSONAPI::Request::QueryParamCollection::QueryParam] The
      #   query params to initialize the collection with
      def initialize(param_arr = [])
        @param_names = []
        super(param_arr, item_type: JSONAPI::Request::QueryParamCollection::QueryParam)
      end
  
      # #empyt? provided by super class
      # #include provided by super class
      
      # Add a QueryParameter to the collection. (CASE-SENSITIVE)
      # @param param [JSONAPI::Request::QueryParamCollection::QueryParam] The param to add
      def add(param)
        super(param, &:name)
      end

      # #<< provided by super, but calls overriden #add
      # #each provided from super
      # #remove provided from super
      # #get provided by super
      # #keys provided by super
      # #size provided by super

      # Represent query param collection like the query_param string
      def to_s
        JSONAPI::Utility.to_string_collection(self, delimiter: '&')
      end

      private

      # Gets the QueryParam object whose name matches the method_name called
      # @param method_name [Symbol] The name of the method called
      # @param args If any arguments were passed to the method called
      # @param block If a block was passed to the method called
      def method_missing(method_name, *args, &block)
        super unless include?(method_name)
        get(method_name)
      end

      # Whether or not method missing should be called.
      def respond_to_missing?(method_name, *)
        include?(method_name) || super
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
easy-jsonapi-1.0.3 lib/easy/jsonapi/request/query_param_collection.rb
easy-jsonapi-1.0.2 lib/easy/jsonapi/request/query_param_collection.rb
easy-jsonapi-1.0.1 lib/easy/jsonapi/request/query_param_collection.rb
easy-jsonapi-1.0.0 lib/easy/jsonapi/request/query_param_collection.rb