Class: Wherewolf::Where::Processor

Inherits:
Processor
  • Object
show all
Defined in:
lib/wherewolf/where/processor.rb

Instance Attribute Summary

Attributes inherited from Processor

#model

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Processor

#initialize

Constructor Details

This class inherits a constructor from Wherewolf::Processor

Class Method Details

.parse(model, query) ⇒ Object



6
7
8
9
# File 'lib/wherewolf/where/processor.rb', line 6

def self.parse(model, query)
  instance = self.new(model, model.wherewolf_options)
  instance.parse(query)
end

Instance Method Details

#parse(query) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/wherewolf/where/processor.rb', line 11

def parse(query)
  begin
    ast = Wherewolf::Where::Parser.new.parse(query)
    table = model.arel_table
    self.model.where(process(ast, table))
  rescue Parslet::ParseFailed => error
    raise Wherewolf::ParseError, error
  end
end

#process(ast, table) ⇒ Object



21
22
23
24
# File 'lib/wherewolf/where/processor.rb', line 21

def process(ast, table)
  operation = ast.keys.first
  self.send("process_#{operation}".to_sym, ast[operation], table) if self.respond_to?("process_#{operation}".to_sym, true)
end