class Eql::Builder
Builder
class builds ERB templates and interact with adapters to run it.
Attributes
@param [String] retruns DB connectionor a currsor
@param [String] returns path to a root folder with templates
Public Class Methods
@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
Proxy's adapter
@retrn [Eql::Adapters::Base]
# File lib/eql/builder.rb, line 70 def adapter @adapter ||= AdapterFactory.factory(conn).new(self) end
Clone current builder
@return [Eql::Builder]
# File lib/eql/builder.rb, line 135 def clone self.class.new(path, conn) end
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 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 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 query's params
@param [Object] params
# File lib/eql/builder.rb, line 52 def load_params(params) @params = params end
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
@return [Eql::TemplateLoader]
# File lib/eql/builder.rb, line 43 def loader @loader ||= TemplateLoader.new(self) end
# File lib/eql/builder.rb, line 101 def method_missing(name, *args, &block) adapter.send(name, *args, &block) end
Proxy
class for template
@return [Eql::Proxy]
# File lib/eql/builder.rb, line 97 def proxy_class Eql::Proxy.generate(adapter) end
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
Set content template
@param [String] raw template's content
# File lib/eql/builder.rb, line 61 def template(raw) @template_content = raw end
Template's content
@return [String]
# File lib/eql/builder.rb, line 79 def template_content @template_content.to_s end