Class: Inquery::Query
- Inherits:
-
Object
- Object
- Inquery::Query
- Includes:
- Mixins::RawSqlUtils, 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.
-
#connection ⇒ Object
Provides a connection to the database.
-
#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).
22 23 24 25 26 27 28 |
# File 'lib/inquery/query.rb', line 22 def initialize(params = {}) @params = params if _schema @params = _schema.validate!(@params) end end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
6 7 8 |
# File 'lib/inquery/query.rb', line 6 def params @params end |
Class Method Details
.call(*args) ⇒ Object
Instantiates the query class using the given arguments
and runs call
on it.
16 17 18 |
# File 'lib/inquery/query.rb', line 16 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.
10 11 12 |
# File 'lib/inquery/query.rb', line 10 def self.run(*args) new(*args).run end |
Instance Method Details
#call ⇒ Object
Override this method to perform the actual query.
36 37 38 |
# File 'lib/inquery/query.rb', line 36 def call fail NotImplementedError end |
#connection ⇒ Object
Provides a connection to the database. May be overridden if a different
connection is desired. Defaults to ActiveRecord::Base.connection
.
53 54 55 |
# File 'lib/inquery/query.rb', line 53 def connection ActiveRecord::Base.connection end |
#osparams ⇒ Object
Returns a copy of the query's params, wrapped in an OpenStruct object for easyer access.
47 48 49 |
# File 'lib/inquery/query.rb', line 47 def osparams @osparams ||= OpenStruct.new(params) end |
#process(results) ⇒ Object
Override this method to perform an optional result postprocessing.
41 42 43 |
# File 'lib/inquery/query.rb', line 41 def process(results) results end |
#run ⇒ Object
Runs both call
and process
.
31 32 33 |
# File 'lib/inquery/query.rb', line 31 def run process(call) end |