Sha256: 051165ce6e74920c75172a2c614493dda68cf2b5405a96aee403ab21315bba30
Contents?: true
Size: 1.05 KB
Versions: 6
Compression:
Stored size: 1.05 KB
Contents
module Ambition module Order def sort_by(&block) query_context.add OrderProcessor.new(self, block) end end class OrderProcessor < Processor def initialize(owner, block) super() @receiver = nil @owner = owner @table_name = owner.table_name @block = block @key = :order end ## # Sexp Processing Methods def process_call(exp) receiver, method, other = *exp exp.clear translation(receiver, method, other) end def process_vcall(exp) if (method = exp.shift) == :rand 'RAND()' else raise "Not implemented: :vcall for #{method}" end end def process_masgn(exp) exp.clear '' end ## # Helpers! def translation(receiver, method, other) case method when :-@ "#{process(receiver)} DESC" when :__send__ "#{@table_name}.#{eval('to_s', @block)}" else extract_includes(receiver, method) || "#{@table_name}.#{method}" end end end end
Version data entries
6 entries across 6 versions & 1 rubygems