Module: DataMapper::Adapters::AbstractAdapter::Quoting

Defined in:
lib/data_mapper/adapters/abstract_adapter.rb

Overview

Quoting is a mixin that extends your DataMapper::Database singleton-class to allow for object-name and value quoting to be exposed to the queries.

DESIGN: Is there any need for this outside of the query objects? Should we just include it in our query object subclasses and not rely on a Quoting mixin being part of the “standard” Adapter interface?

Instance Method Summary collapse

Instance Method Details

#quote_column_name(name) ⇒ Object



112
113
114
# File 'lib/data_mapper/adapters/abstract_adapter.rb', line 112

def quote_column_name(name)
  name.ensure_wrapped_with('"')
end

#quote_table_name(name) ⇒ Object



108
109
110
# File 'lib/data_mapper/adapters/abstract_adapter.rb', line 108

def quote_table_name(name)
  name.ensure_wrapped_with('"')
end

#quote_value(value) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/data_mapper/adapters/abstract_adapter.rb', line 116

def quote_value(value)
  return 'NULL' if value.nil?

  case value
    when Numeric then value.to_s
    when String then "'#{value.gsub("'", "''")}'"
    when Class then "'#{value.name}'"
    when Date then "'#{value.to_s}'"
    when Time, DateTime then "'#{value.strftime("%Y-%m-%d %H:%M:%S")}'"
    when TrueClass, FalseClass then value.to_s.upcase
    else raise "Don't know how to quote #{value.inspect}"
  end
end