Method: Blazer::DataSource#quote

Defined in:
lib/blazer/data_source.rb

#quote(value) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/blazer/data_source.rb', line 151

def quote(value)
  if quoting == :backslash_escape || quoting == :single_quote_escape
    # only need to support types generated by process_vars
    if value.is_a?(Integer) || value.is_a?(Float)
      value.to_s
    elsif value.nil?
      "NULL"
    else
      value = value.to_formatted_s(:db) if value.is_a?(ActiveSupport::TimeWithZone)

      if quoting == :backslash_escape
        "'#{value.gsub("\\") { "\\\\" }.gsub("'") { "\\'" }}'"
      else
        "'#{value.gsub("'", "''")}'"
      end
    end
  elsif quoting.respond_to?(:call)
    quoting.call(value)
  elsif quoting.nil?
    raise Blazer::Error, "Quoting not specified"
  else
    raise Blazer::Error, "Unknown quoting"
  end
end