Class: Inquery::Query
- Inherits:
-
Object
- Object
- Inquery::Query
- Includes:
- Mixins::SchemaValidation
- Defined in:
- lib/inquery/query.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Chainable
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.call(*args) ⇒ Object
Instantiates the query class using the given arguments and runs
call
on it. -
.run(*args) ⇒ Object
Instantiates the query class using the given arguments and runs
call
andprocess
on it.
Instance Method Summary collapse
-
#call ⇒ Object
Override this method to perform the actual query.
-
#initialize(params = {}) ⇒ Query
constructor
Instantiates the query class and validates the given params hash (if there was a validation schema specified).
-
#osparams ⇒ Object
Returns a copy of the query's params, wrapped in an OpenStruct object for easyer access.
-
#process(results) ⇒ Object
Override this method to perform an optional result postprocessing.
-
#run ⇒ Object
Runs both
call
andprocess
.
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
#params ⇒ Object (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
#call ⇒ Object
Override this method to perform the actual query.
35 36 37 |
# File 'lib/inquery/query.rb', line 35 def call fail NotImplementedError end |
#osparams ⇒ Object
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 |
#run ⇒ Object
Runs both call
and process
.
30 31 32 |
# File 'lib/inquery/query.rb', line 30 def run process(call) end |