./lib/ambition/where.rb in ambition-0.1.1 vs ./lib/ambition/where.rb in ambition-0.1.2
- old
+ new
@@ -8,20 +8,17 @@
select(&block).first
end
end
class WhereProcessor < Processor
- attr_reader :includes
-
def initialize(owner, block)
super()
@receiver = nil
@owner = owner
@table_name = owner.table_name
@block = block
@key = :conditions
- @includes = []
end
##
# Sexp Processing Methods
def process_and(exp)
@@ -136,23 +133,10 @@
when '=~'
"#{process(receiver)} LIKE #{process(other)}"
when '!~'
"#{process(receiver)} NOT LIKE #{process(other)}"
else
- build_condition(receiver, method, other)
- end
- end
-
- def build_condition(receiver, method, other)
- if receiver.first == :call && receiver[1].last == @receiver
- if reflection = @owner.reflections[receiver.last]
- @includes << reflection.name unless @includes.include? reflection.name
- "#{reflection.table_name}.#{method}"
- else
- raise "No reflection `#{receiver.last}' found on #{@owner}"
- end
- else
- "#{process(receiver)}.`#{method}` #{process(other)}"
+ extract_includes(receiver, method) || "#{process(receiver)}.`#{method}` #{process(other)}"
end
end
end
end