class Bmg::Sql::Processor::Transform

Attributes

transformation[R]

Public Class Methods

new(transformation, options, builder) click to toggle source
Calls superclass method Bmg::Sql::Processor::new
# File lib/bmg/sql/processor/transform.rb, line 42
def initialize(transformation, options, builder)
  raise NotSupportedError unless options.empty?
  super(builder)
  @transformation = transformation
end
split_supported(*args, &bl) click to toggle source
# File lib/bmg/sql/processor/transform.rb, line 49
def self.split_supported(*args, &bl)
  SplitSupported.split_supported(*args, &bl)
end

Public Instance Methods

on_select_item(sexpr) click to toggle source
# File lib/bmg/sql/processor/transform.rb, line 59
def on_select_item(sexpr)
  as = sexpr.as_name.to_sym
  case t = transformation_for(as)
  when NilClass
    sexpr
  when Class, Array
    sexpr([:select_item,
      func_call_node(sexpr, Array(t).reverse),
      sexpr[2]
    ])
  else
    raise NotSupportedError
  end
end
on_select_list(sexpr) click to toggle source
# File lib/bmg/sql/processor/transform.rb, line 53
def on_select_list(sexpr)
  sexpr.each_with_index.map{|child,index|
    index == 0 ? child : apply(child)
  }
end

Private Instance Methods

_func_call_node(sexpr, head, tail) click to toggle source
# File lib/bmg/sql/processor/transform.rb, line 80
def _func_call_node(sexpr, head, tail)
  inside = if tail.empty?
    sexpr[1]
  else
    _func_call_node(sexpr, tail.first, tail[1..-1])
  end
  [:func_call,
    :cast,
    inside,
    [ :literal, head ] ]
end
func_call_node(sexpr, ts) click to toggle source
# File lib/bmg/sql/processor/transform.rb, line 76
def func_call_node(sexpr, ts)
  _func_call_node(sexpr, ts.first, ts[1..-1])
end
transformation_for(as) click to toggle source
# File lib/bmg/sql/processor/transform.rb, line 92
def transformation_for(as)
  case t = transformation
  when Class then t
  when Hash  then t[as]
  when Array then t
  else
    raise Sql::NotSupportedError, "Unable to use `#{as}` for `transform`"
  end
end