Class: HSQL::Template
- Inherits:
-
Object
- Object
- HSQL::Template
- Defined in:
- lib/hsql/template.rb
Overview
Given some SQL that may contain Mustache tags (e.g. variable }} ), accept a hash of data that interpolates each tag. Throws an error if one of the tag names can’t be found in the data.
Defined Under Namespace
Classes: FormatError
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
-
#initialize(input, verbose) ⇒ Template
constructor
A new instance of Template.
- #render(hash) ⇒ Object
Constructor Details
#initialize(input, verbose) ⇒ Template
Returns a new instance of Template.
13 14 15 16 |
# File 'lib/hsql/template.rb', line 13 def initialize(input, verbose) @input = input @verbose = verbose end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
7 8 9 |
# File 'lib/hsql/template.rb', line 7 def input @input end |
Instance Method Details
#render(hash) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hsql/template.rb', line 18 def render(hash) Mustache.raise_on_context_miss = true output = Mustache.render(input, hash) if @verbose warn '-- Rendered SQL:' warn output end output rescue Mustache::ContextMiss => e fail_with(e., hash.keys.sort) end |