Parent

Methods

Class Index [+]

Quicksearch

Sequel::ASTTransformer

The ASTTransformer class is designed to handle the abstract syntax trees that Sequel uses internally and produce modified copies of them. By itself it only produces a straight copy. It’s designed to be subclassed and have subclasses returned modified copies of the specific nodes that need to be modified.

Public Instance Methods

transform(obj) click to toggle source

Return obj or a potentially transformed version of it.

    # File lib/sequel/ast_transformer.rb, line 9
 9:     def transform(obj)
10:       v(obj)
11:     end

Private Instance Methods

v(o) click to toggle source

Recursive version that handles all of Sequel’s internal object types and produces copies of them.

    # File lib/sequel/ast_transformer.rb, line 17
17:     def v(o)
18:       case o
19:       when Symbol, Numeric, String, Class, TrueClass, FalseClass, NilClass
20:         o
21:       when Array
22:         o.map{|x| v(x)}
23:       when Hash
24:         h = {}
25:         o.each{|k, val| h[v(k)] = v(val)}
26:         h
27:       when SQL::ComplexExpression
28:         SQL::ComplexExpression.new(o.op, *v(o.args))
29:       when SQL::Identifier
30:         SQL::Identifier.new(v(o.value))
31:       when SQL::QualifiedIdentifier
32:         SQL::QualifiedIdentifier.new(v(o.table), v(o.column))
33:       when SQL::OrderedExpression
34:         SQL::OrderedExpression.new(v(o.expression), o.descending, :nulls=>o.nulls)
35:       when SQL::AliasedExpression
36:         SQL::AliasedExpression.new(v(o.expression), o.aliaz)
37:       when SQL::CaseExpression
38:         args = [v(o.conditions), v(o.default)]
39:         args << v(o.expression) if o.expression?
40:         SQL::CaseExpression.new(*args)
41:       when SQL::Cast
42:         SQL::Cast.new(v(o.expr), o.type)
43:       when SQL::Function
44:         SQL::Function.new(o.f, *v(o.args))
45:       when SQL::Subscript
46:         SQL::Subscript.new(v(o.f), v(o.sub))
47:       when SQL::WindowFunction
48:         SQL::WindowFunction.new(v(o.function), v(o.window))
49:       when SQL::Window
50:         opts = o.opts.dup
51:         opts[:partition] = v(opts[:partition]) if opts[:partition]
52:         opts[:order] = v(opts[:order]) if opts[:order]
53:         SQL::Window.new(opts)
54:       when SQL::PlaceholderLiteralString
55:         args = if o.args.is_a?(Hash)
56:           h = {}
57:           o.args.each{|k,val| h[k] = v(val)}
58:           h
59:         else
60:           v(o.args)
61:         end
62:         SQL::PlaceholderLiteralString.new(o.str, args, o.parens)
63:       when SQL::JoinOnClause
64:         SQL::JoinOnClause.new(v(o.on), o.join_type, v(o.table), v(o.table_alias))
65:       when SQL::JoinUsingClause
66:         SQL::JoinUsingClause.new(v(o.using), o.join_type, v(o.table), v(o.table_alias))
67:       when SQL::JoinClause
68:         SQL::JoinClause.new(o.join_type, v(o.table), v(o.table_alias))
69:       when SQL::Wrapper
70:         SQL::Wrapper.new(v(o.value))
71:       else
72:         o
73:       end
74:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.