Class: ActiveRecordQuery::Conditions::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_query/conditions/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource, context) ⇒ Builder

Returns a new instance of Builder.



4
5
6
7
# File 'lib/active_record_query/conditions/builder.rb', line 4

def initialize(resource, context)
  @resource = resource
  @context = context
end

Instance Method Details

#build(group) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_record_query/conditions/builder.rb', line 9

def build(group)
  chain_conditions = nil
  arg_stacker = ArgumentStacker.new(group, :condition)
  arg_stacker.list.each do |chain_link|
    next unless executable?(chain_link)
    if chain_link.respond_to?(:where)
      group = chain_link.new
      chain_conditions = chain_conditions.present? ? chain_conditions.send(chain_link::glue, build(group)) : build(group)
    else
      arel_condition = ExpressionParser.new(context).parse(chain_link.condition)
      chain_conditions = chain_conditions.present? ? chain_conditions.send(chain_link.type, arel_condition) : arel_condition
    end
  end
  resource.arel_table.grouping(chain_conditions) if chain_conditions
end