Class: Eql::Builder
- Inherits:
-
Object
- Object
- Eql::Builder
- Defined in:
- lib/eql/builder.rb
Overview
Builder class builds ERB templates and interact with adapters to run it.
Instance Attribute Summary collapse
- #conn ⇒ Object readonly
- #path ⇒ Object readonly
Instance Method Summary collapse
-
#adapter ⇒ Object
Proxy’s adapter.
-
#clone ⇒ Eql::Builder
Clone current builder.
-
#execute(tmpl = nil, params = nil) ⇒ Object
Execute template query.
-
#execute_params(params = nil) ⇒ Object
Execute params with a query.
-
#initialize(path, conn) ⇒ Builder
constructor
A new instance of Builder.
-
#load(name = nil, params = nil) ⇒ Object
Load query’s template and params.
-
#load_params(params) ⇒ Object
Load query’s params.
-
#load_template(name) ⇒ Object
Load template with given name.
- #loader ⇒ Eql::TemplateLoader
- #method_missing(name, *args, &block) ⇒ Object
-
#proxy_class ⇒ Eql::Proxy
Proxy class for template.
-
#render ⇒ String
Render a template.
-
#template(raw) ⇒ Object
Set content template.
-
#template_content ⇒ String
Template’s content.
Constructor Details
#initialize(path, conn) ⇒ Builder
Returns a new instance of Builder.
15 16 17 18 |
# File 'lib/eql/builder.rb', line 15 def initialize(path, conn) @path = Array.wrap(path) @conn = conn end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
101 102 103 |
# File 'lib/eql/builder.rb', line 101 def method_missing(name, *args, &block) adapter.send(name, *args, &block) end |
Instance Attribute Details
#conn ⇒ Object (readonly)
9 10 11 |
# File 'lib/eql/builder.rb', line 9 def conn @conn end |
#path ⇒ Object (readonly)
7 8 9 |
# File 'lib/eql/builder.rb', line 7 def path @path end |
Instance Method Details
#adapter ⇒ Object
Proxy’s adapter
70 71 72 |
# File 'lib/eql/builder.rb', line 70 def adapter @adapter ||= AdapterFactory.factory(conn).new(self) end |
#clone ⇒ Eql::Builder
Clone current builder
135 136 137 |
# File 'lib/eql/builder.rb', line 135 def clone self.class.new(path, conn) end |
#execute(tmpl = nil, params = nil) ⇒ Object
Execute template query
113 114 115 116 |
# File 'lib/eql/builder.rb', line 113 def execute(tmpl = nil, params = nil) load(tmpl, params) adapter.execute end |
#execute_params(params = nil) ⇒ Object
Execute params with a query
125 126 127 128 |
# File 'lib/eql/builder.rb', line 125 def execute_params(params = nil) load_params(params) adapter.execute end |
#load(name = nil, params = nil) ⇒ Object
Load query’s template and params
26 27 28 29 |
# 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) ⇒ Object
Load query’s params
52 53 54 |
# File 'lib/eql/builder.rb', line 52 def load_params(params) @params = params end |
#load_template(name) ⇒ Object
Load template with given name
36 37 38 |
# File 'lib/eql/builder.rb', line 36 def load_template(name) @template_content = loader.load_template(name) end |
#loader ⇒ Eql::TemplateLoader
43 44 45 |
# File 'lib/eql/builder.rb', line 43 def loader @loader ||= TemplateLoader.new(self) end |
#proxy_class ⇒ Eql::Proxy
Proxy class for template
97 98 99 |
# File 'lib/eql/builder.rb', line 97 def proxy_class Eql::Proxy.generate(adapter) end |
#render ⇒ String
Render a template
88 89 90 |
# File 'lib/eql/builder.rb', line 88 def render ERB.new(template_content).result(proxy_class.new(self, @params).get_binding) end |
#template(raw) ⇒ Object
Set content template
61 62 63 |
# File 'lib/eql/builder.rb', line 61 def template(raw) @template_content = raw end |
#template_content ⇒ String
Template’s content
79 80 81 |
# File 'lib/eql/builder.rb', line 79 def template_content @template_content.to_s end |