Class: Inquery::Query

Inherits:
Object
  • Object
show all
Includes:
Mixins::SchemaValidation
Defined in:
lib/inquery/query.rb

Direct Known Subclasses

Chainable

Defined Under Namespace

Classes: Chainable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Query

Instantiates the query class and validates the given params hash (if there was a validation schema specified).



21
22
23
24
25
26
27
# File 'lib/inquery/query.rb', line 21

def initialize(params = {})
  @params = params

  if self.class._schema
    Schemacop.validate!(self.class._schema, @params)
  end
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Class Method Details

.call(*args) ⇒ Object

Instantiates the query class using the given arguments and runs call on it.



15
16
17
# File 'lib/inquery/query.rb', line 15

def self.call(*args)
  new(*args).call
end

.run(*args) ⇒ Object

Instantiates the query class using the given arguments and runs call and process on it.



9
10
11
# File 'lib/inquery/query.rb', line 9

def self.run(*args)
  new(*args).run
end

Instance Method Details

#callObject

Override this method to perform the actual query.



35
36
37
# File 'lib/inquery/query.rb', line 35

def call
  fail NotImplementedError
end

#osparamsObject

Returns a copy of the query's params, wrapped in an OpenStruct object for easyer access.



46
47
48
# File 'lib/inquery/query.rb', line 46

def osparams
  @osparams ||= OpenStruct.new(params)
end

#process(results) ⇒ Object

Override this method to perform an optional result postprocessing.



40
41
42
# File 'lib/inquery/query.rb', line 40

def process(results)
  results
end

#runObject

Runs both call and process.



30
31
32
# File 'lib/inquery/query.rb', line 30

def run
  process(call)
end