class Eql::Builder

Builder class builds ERB templates and interact with adapters to run it.

Attributes

conn[R]

@param [String] retruns DB connectionor a currsor

path[R]

@param [String] returns path to a root folder with templates

Public Class Methods

new(path, conn) click to toggle source

@param [Array<String>, String] path path to a root folder with templates @param [String] conn DB connection or a cursor

# File lib/eql/builder.rb, line 15
def initialize(path, conn)
  @path = Array.wrap(path)
  @conn = conn
end

Public Instance Methods

adapter() click to toggle source

Proxy's adapter

@retrn [Eql::Adapters::Base]

# File lib/eql/builder.rb, line 70
def adapter
  @adapter ||= AdapterFactory.factory(conn).new(self)
end
clone() click to toggle source

Clone current builder

@return [Eql::Builder]

# File lib/eql/builder.rb, line 135
def clone
  self.class.new(path, conn)
end
execute(tmpl = nil, params = nil) click to toggle source

Execute template query

@param [String, Symbol] tmpl template's name @param [Object, nil] params query params

@return [Object] returns execution results

# File lib/eql/builder.rb, line 113
def execute(tmpl = nil, params = nil)
  load(tmpl, params)
  adapter.execute
end
execute_params(params = nil) click to toggle source

Execute params with a query

@param [Object] params

@return [Object] returns execution results

# File lib/eql/builder.rb, line 125
def execute_params(params = nil)
  load_params(params)
  adapter.execute
end
load(name = nil, params = nil) click to toggle source

Load query's template and params

@param [String] name template's name @param [Object] params query's params

# File lib/eql/builder.rb, line 26
def load(name = nil, params = nil)
  load_template(name) if name
  load_params(params) if params
end
load_params(params) click to toggle source

Load query's params

@param [Object] params

# File lib/eql/builder.rb, line 52
def load_params(params)
  @params = params
end
load_template(name) click to toggle source

Load template with given name

@param [String, Symbol] name template's name

# File lib/eql/builder.rb, line 36
def load_template(name)
  @template_content = loader.load_template(name)
end
loader() click to toggle source

@return [Eql::TemplateLoader]

# File lib/eql/builder.rb, line 43
def loader
  @loader ||= TemplateLoader.new(self)
end
method_missing(name, *args, &block) click to toggle source
# File lib/eql/builder.rb, line 101
def method_missing(name, *args, &block)
  adapter.send(name, *args, &block)
end
proxy_class() click to toggle source

Proxy class for template

@return [Eql::Proxy]

# File lib/eql/builder.rb, line 97
def proxy_class
  Eql::Proxy.generate(adapter)
end
render() click to toggle source

Render a template

@return [String] returns rendered templated

# File lib/eql/builder.rb, line 88
def render
  ERB.new(template_content).result(proxy_class.new(self, @params).get_binding)
end
template(raw) click to toggle source

Set content template

@param [String] raw template's content

# File lib/eql/builder.rb, line 61
def template(raw)
  @template_content = raw
end
template_content() click to toggle source

Template's content

@return [String]

# File lib/eql/builder.rb, line 79
def template_content
  @template_content.to_s
end