./lib/ambition/processor.rb in ambition-0.1.1 vs ./lib/ambition/processor.rb in ambition-0.1.2

- old
+ new

@@ -2,19 +2,21 @@ module Ambition class Processor < SexpProcessor include ActiveRecord::ConnectionAdapters::Quoting - attr_reader :key, :join_string, :prefix + attr_reader :key, :join_string, :prefix, :includes + def initialize super() @strict = false @expected = String @auto_shift_type = true @warn_on_default = false @default_method = :process_error + @includes = [] end ## # Processing methods def process_error(exp) @@ -46,9 +48,20 @@ def sanitize(value) case value.to_s when 'true' then '1' when 'false' then '0' else ActiveRecord::Base.connection.quote(value) rescue quote(value) + end + end + + def extract_includes(receiver, method) + return unless 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 end end end