Class: ErbSqlTemplates::TemplateScope

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

Instance Method Summary collapse

Constructor Details

#initialize(connection, hash) ⇒ TemplateScope

Returns a new instance of TemplateScope.



49
50
51
52
# File 'lib/erb_sql_templates.rb', line 49

def initialize(connection, hash)
  @connection = connection
  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.



65
66
67
68
69
70
71
# File 'lib/erb_sql_templates.rb', line 65

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.



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

def get_binding
  binding()
end

#h(value) ⇒ Object

helper for sanitizing sql inputs



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

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