Sha256: c6b125ecf09c935aa8abb17b1beaeccbc0b32e0d82e4e9351dc0f3e2d66058ff

Contents?: true

Size: 877 Bytes

Versions: 10

Compression:

Stored size: 877 Bytes

Contents

require 'active_record/sanitization'

module ActiveRecord
  module Sanitization
    extend ActiveSupport::Concern

    module ClassMethods
      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

      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
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
activerecord-postgis-array-0.3.4 lib/activerecord-postgis-array/active_record/sanitization.rb
postgres_ext-1.0.0 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.4.0 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.3.1 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.3.0 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.2.2 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.2.1 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.2.0 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.1.0 lib/postgres_ext/active_record/sanitization.rb
postgres_ext-0.0.10 lib/postgres_ext/active_record/sanitization.rb