Class: ScopedFrom::Query

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  self.relation = relation
  self.options = options
  self.params = params
end

Instance Attribute Details

#paramsObject

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_columnObject



19
20
21
# File 'lib/scoped_from/query.rb', line 19

def order_column
  parse_order(params['order'])[:column]
end

#order_directionObject



23
24
25
# File 'lib/scoped_from/query.rb', line 23

def order_direction
  parse_order(params['order'])[:direction]
end

#relationObject



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