Class: SQL::Composer::DSL

Inherits:
BasicObject
Defined in:
lib/sql/composer/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ DSL

Returns a new instance of DSL.



20
21
22
23
24
25
26
27
28
# File 'lib/sql/composer/dsl.rb', line 20

def initialize(options, &block)
  @options = options
  @ast = []
  @tokens = options[:tokens] || Tokens.new

  with_tokens(tokens) do
    instance_exec(*options[:args], &block)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



41
42
43
44
# File 'lib/sql/composer/dsl.rb', line 41

def method_missing(name, *args)
  ast << [name.to_s.downcase, *args]
  self
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



16
17
18
# File 'lib/sql/composer/dsl.rb', line 16

def ast
  @ast
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/sql/composer/dsl.rb', line 14

def options
  @options
end

#tokensObject (readonly)

Returns the value of attribute tokens.



18
19
20
# File 'lib/sql/composer/dsl.rb', line 18

def tokens
  @tokens
end

Instance Method Details

#`(value) ⇒ Object



35
36
37
# File 'lib/sql/composer/dsl.rb', line 35

def `(value)
  Nodes::Literal.new(value: value, backend: options[:backend])
end

#callObject



30
31
32
33
# File 'lib/sql/composer/dsl.rb', line 30

def call
  compiler = Compiler.new(options.fetch(:backend), tokens: tokens)
  compiler.(ast)
end