Class: Bmg::Sql::Processor::Reorder

Inherits:
Bmg::Sql::Processor show all
Defined in:
lib/bmg/sql/processor/reorder.rb

Constant Summary

Constants inherited from Bmg::Sql::Processor

UnexpectedError

Instance Attribute Summary

Attributes inherited from Bmg::Sql::Processor

#builder

Instance Method Summary collapse

Methods inherited from Bmg::Sql::Processor

#on_select_exp, #on_set_operator, #on_with_exp

Constructor Details

#initialize(attr_list, builder) ⇒ Reorder

Returns a new instance of Reorder.



6
7
8
9
# File 'lib/bmg/sql/processor/reorder.rb', line 6

def initialize(attr_list, builder)
  super(builder)
  @indexes = Hash[attr_list.to_a.map(&:to_s).each_with_index.to_a]
end

Instance Method Details

#on_select_list(sexpr) ⇒ Object



11
12
13
14
15
16
# File 'lib/bmg/sql/processor/reorder.rb', line 11

def on_select_list(sexpr)
  reordered = sexpr.sexpr_body.sort{|i1,i2|
    @indexes[i1.as_name.to_s] <=> @indexes[i2.as_name.to_s]
  }
  reordered.unshift(:select_list)
end