Class: Bmg::Sql::Processor::Rename

Inherits:
Bmg::Sql::Processor show all
Defined in:
lib/bmg/sql/processor/rename.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(renaming, builder) ⇒ Rename

Returns a new instance of Rename.



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

def initialize(renaming, builder)
  super(builder)
  @renaming = renaming
end

Instance Method Details

#on_select_item(sexpr) ⇒ Object



17
18
19
20
# File 'lib/bmg/sql/processor/rename.rb', line 17

def on_select_item(sexpr)
  return sexpr unless newname = @renaming[sexpr.as_name.to_sym]
  builder.select_item(sexpr.qualifier, sexpr.would_be_name, newname.to_s)
end

#on_select_list(sexpr) ⇒ Object



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

def on_select_list(sexpr)
  sexpr.each_with_index.map{|child,index|
    index == 0 ? child : apply(child)
  }
end