Class: ScopedFrom::Query
- Inherits:
-
Object
- Object
- ScopedFrom::Query
- Defined in:
- lib/scoped_from/query.rb
Constant Summary collapse
- FALSE_VALUES =
%w(false no n off 0).freeze
- ORDER_DIRECTIONS =
%w(asc desc).freeze
- TRUE_VALUES =
%w(true yes y on 1).freeze
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(relation, params, options = {}) ⇒ Query
constructor
Available options are: - :only : to restrict to specified keys.
- #order_column ⇒ Object
- #order_direction ⇒ Object
- #relation ⇒ Object
Constructor Details
#initialize(relation, params, options = {}) ⇒ Query
Available options are: - :only : to restrict to specified keys.
- :except : to ignore specified keys.
13 14 15 16 17 |
# File 'lib/scoped_from/query.rb', line 13 def initialize(relation, params, = {}) self.relation = relation self. = self.params = params end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/scoped_from/query.rb', line 9 def params @params end |
Instance Method Details
#order_column ⇒ Object
19 20 21 |
# File 'lib/scoped_from/query.rb', line 19 def order_column parse_order(params['order'])[:column] end |
#order_direction ⇒ Object
23 24 25 |
# File 'lib/scoped_from/query.rb', line 23 def order_direction parse_order(params['order'])[:direction] end |
#relation ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/scoped_from/query.rb', line 27 def relation relation = @relation params.each do |name, value| [value].flatten.each do |value| relation = invoke_param(relation, name, value) end end decorate_relation(relation) end |