Sha256: cf29fdba7a87b356ac8ee2c35c5730f5d4adfebdd369b19e7123bfc7b9b2c142

Contents?: true

Size: 763 Bytes

Versions: 3

Compression:

Stored size: 763 Bytes

Contents

module JsonApiClient
  module Query
    class Base
      class_attribute :request_method
      attr_reader :klass, :headers, :path, :params

      def initialize(klass, args)
        @klass = klass
        build_params(args)
        @headers = klass.default_headers.dup

        @path = begin
          p = klass.path(@params)
          if @params.has_key?(klass.primary_key) && !@params[klass.primary_key].is_a?(Array)
            p = File.join(p, @params.delete(klass.primary_key).to_s)
          end
          p
        end
      end

      def build_params(args)
        @params = args.dup
      end

      def inspect
        "#{self.class.name}: method: #{request_method}; path: #{path}; params: #{params}, headers: #{headers}"
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
json_api_client-0.7.1 lib/json_api_client/query/base.rb
json_api_client-0.7.0 lib/json_api_client/query/base.rb
json_api_client-0.6.0 lib/json_api_client/query/base.rb