Class: JsonApiClient::Query::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/json_api_client/query/base.rb

Direct Known Subclasses

Create, Custom, Destroy, Find, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, args) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/json_api_client/query/base.rb', line 7

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

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/json_api_client/query/base.rb', line 5

def headers
  @headers
end

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/json_api_client/query/base.rb', line 5

def klass
  @klass
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/json_api_client/query/base.rb', line 5

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/json_api_client/query/base.rb', line 5

def path
  @path
end

Instance Method Details

#build_params(args) ⇒ Object



21
22
23
# File 'lib/json_api_client/query/base.rb', line 21

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

#inspectObject



25
26
27
# File 'lib/json_api_client/query/base.rb', line 25

def inspect
  "method: #{request_method}; path: #{path}; params: #{params}, headers: #{headers}"
end