Class: Bmg::Sql::Processor::Transform
- Inherits:
-
Processor
- Object
- Processor
- Bmg::Sql::Processor::Transform
- Defined in:
- lib/bmg/sql/processor/transform.rb
Defined Under Namespace
Modules: SplitSupported
Instance Attribute Summary collapse
-
#transformation ⇒ Object
readonly
Returns the value of attribute transformation.
Class Method Summary collapse
- .split_supported(*args, &bl) ⇒ Object
-
.sql_expr?(x) ⇒ Boolean
An SQL-able element the transform can emit verbatim: an object that carries its own SQL (the predicate gem's
:sql/:sql_literalconvention) or a Sequel expression (rendered throughSequel.expr).
Instance Method Summary collapse
-
#initialize(transformation, options, builder) ⇒ Transform
constructor
module SplitSupported.
- #on_select_item(sexpr) ⇒ Object
- #on_select_list(sexpr) ⇒ Object
Constructor Details
#initialize(transformation, options, builder) ⇒ Transform
module SplitSupported
42 43 44 45 46 |
# File 'lib/bmg/sql/processor/transform.rb', line 42 def initialize(transformation, , builder) raise NotSupportedError unless .empty? super(builder) @transformation = transformation end |
Instance Attribute Details
#transformation ⇒ Object (readonly)
Returns the value of attribute transformation.
47 48 49 |
# File 'lib/bmg/sql/processor/transform.rb', line 47 def transformation @transformation end |
Class Method Details
.split_supported(*args, &bl) ⇒ Object
49 50 51 |
# File 'lib/bmg/sql/processor/transform.rb', line 49 def self.split_supported(*args, &bl) SplitSupported.split_supported(*args, &bl) end |
.sql_expr?(x) ⇒ Boolean
An SQL-able element the transform can emit verbatim: an object that
carries its own SQL (the predicate gem's :sql/:sql_literal
convention) or a Sequel expression (rendered through Sequel.expr).
56 57 58 59 |
# File 'lib/bmg/sql/processor/transform.rb', line 56 def self.sql_expr?(x) x.respond_to?(:sql_literal) || x.respond_to?(:sql) || (defined?(::Sequel::SQL::Expression) && x.is_a?(::Sequel::SQL::Expression)) end |
Instance Method Details
#on_select_item(sexpr) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bmg/sql/processor/transform.rb', line 67 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] ]) when Hash sexpr([:select_item, case_when_node(sexpr, t), sexpr[2] ]) else # An SQL-able value (e.g. a Sequel expression) carries its own SQL # — including the column reference — so it rides through as a # literal, which the Sequel translator emits verbatim. raise NotSupportedError unless Transform.sql_expr?(t) sexpr([:select_item, [:literal, t], sexpr[2]]) end end |
#on_select_list(sexpr) ⇒ Object
61 62 63 64 65 |
# File 'lib/bmg/sql/processor/transform.rb', line 61 def on_select_list(sexpr) sexpr.each_with_index.map{|child,index| index == 0 ? child : apply(child) } end |