Module: ActiveRecord::Sanitization::ClassMethods

Defined in:
lib/activerecord-postgis-array/active_record/sanitization.rb

Instance Method Summary collapse

Instance Method Details

#quote_bound_value(value, column = nil, c = connection) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/activerecord-postgis-array/active_record/sanitization.rb', line 14

def quote_bound_value(value, column = nil, c = connection)
  if column.present? && column != c
    record_column = self.columns.select {|col| col.name == column}.first
    c.quote(value, record_column)
  elsif value.respond_to?(:map) && !value.acts_like?(:string)
    if value.respond_to?(:empty?) && value.empty?
      c.quote(nil)
    else
      value.map { |v| c.quote(v) }.join(',')
    end
  else
    c.quote(value)
  end
end

#sanitize_sql_hash_for_assignment(attrs) ⇒ Object



8
9
10
11
12
# File 'lib/activerecord-postgis-array/active_record/sanitization.rb', line 8

def sanitize_sql_hash_for_assignment(attrs)
  attrs.map do |attr, value|
    "#{connection.quote_column_name(attr)} = #{quote_bound_value(value, attr)}"
  end.join(', ')
end