Class: ErbSqlTemplates::TemplateScope

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/erb_sql_templates.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder, hash) ⇒ TemplateScope

Returns a new instance of TemplateScope.



56
57
58
59
# File 'lib/erb_sql_templates.rb', line 56

def initialize(builder, hash)
  @builder = builder
  super hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(prop, *args) ⇒ Object

Raise exeption if you try to use a property that does not exist.



76
77
78
79
80
81
82
# File 'lib/erb_sql_templates.rb', line 76

def method_missing(prop, *args)
  if prop.to_s.include?('=') || (@table != nil && (@table.has_key?(prop) || self.respond_to?(prop))  )
    super
  else
    raise NoMethodError, "No property `#{prop}` set for this SQL.", caller(1)
  end
end

Instance Method Details

#get_bindingObject

Expose private binding() method.



71
72
73
# File 'lib/erb_sql_templates.rb', line 71

def get_binding
  binding()
end

#h(value) ⇒ Object

helper for sanitizing sql inputs



66
67
68
# File 'lib/erb_sql_templates.rb', line 66

def h(value)
  return @builder.connection.quote(value)
end

#render(template_name, **args) ⇒ Object



61
62
63
# File 'lib/erb_sql_templates.rb', line 61

def render(template_name, **args)
  return @builder.render(template_name, **args)
end