Class: Parelation::Criteria::Where::DirectionalQueryApplier

Inherits:
Object
  • Object
show all
Defined in:
lib/parelation/criteria/where/directional_query_applier.rb

Constant Summary collapse

OPERATOR_MAPPING =

Returns keyword to operator mappings.

Returns:

  • (Hash)

    keyword to operator mappings

{
  "where_gt" => ">",
  "where_gte" => ">=",
  "where_lt" => "<",
  "where_lte" => "<="
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator, criteria, chain) ⇒ DirectionalQueryApplier

Returns a new instance of DirectionalQueryApplier.

Parameters:

  • operator (String)

    the named operator from the params

  • criteria (Hash)

    the data to build query operations with

  • chain (ActiveRecord::Relation)

    the chain to apply to



28
29
30
31
32
# File 'lib/parelation/criteria/where/directional_query_applier.rb', line 28

def initialize(operator, criteria, chain)
  @operator = operator
  @criteria = criteria
  @chain = chain
end

Instance Attribute Details

#chainActiveRecord::Relation (readonly)

Returns:

  • (ActiveRecord::Relation)


22
23
24
# File 'lib/parelation/criteria/where/directional_query_applier.rb', line 22

def chain
  @chain
end

#criteriaHash (readonly)

Returns:

  • (Hash)


18
19
20
# File 'lib/parelation/criteria/where/directional_query_applier.rb', line 18

def criteria
  @criteria
end

#operatorString (readonly)

Returns:

  • (String)


14
15
16
# File 'lib/parelation/criteria/where/directional_query_applier.rb', line 14

def operator
  @operator
end

Instance Method Details

#applyActiveRecord::Relation

Returns the chain with newly applied operations.

Returns:

  • (ActiveRecord::Relation)

    the chain with newly applied operations



36
37
38
39
40
# File 'lib/parelation/criteria/where/directional_query_applier.rb', line 36

def apply
  criteria.inject(chain) do |chain, (key, value)|
    chain.where(sql, key, value)
  end
end