Sha256: 5c40eae234b101c93400ac4bcd09be2e5539a13588ddc465186ab7a2f4e3347e

Contents?: true

Size: 881 Bytes

Versions: 20

Compression:

Stored size: 881 Bytes

Contents

module ActiveRecord
  module TypeCaster
    class Connection # :nodoc:
      def initialize(klass, table_name)
        @klass = klass
        @table_name = table_name
      end

      def type_cast_for_database(attribute_name, value)
        return value if value.is_a?(Arel::Nodes::BindParam)
        column = column_for(attribute_name)
        connection.type_cast_from_column(column, value)
      end

      # TODO Change this to private once we've dropped Ruby 2.2 support.
      # Workaround for Ruby 2.2 "private attribute?" warning.
      protected

        attr_reader :table_name
        delegate :connection, to: :@klass

      private

        def column_for(attribute_name)
          if connection.schema_cache.data_source_exists?(table_name)
            connection.schema_cache.columns_hash(table_name)[attribute_name.to_s]
          end
        end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
activerecord-5.1.7 lib/active_record/type_caster/connection.rb
activerecord-5.1.7.rc1 lib/active_record/type_caster/connection.rb
activerecord-5.1.6.2 lib/active_record/type_caster/connection.rb
activerecord-5.1.6.1 lib/active_record/type_caster/connection.rb
activerecord-5.1.6 lib/active_record/type_caster/connection.rb
activerecord-5.1.5 lib/active_record/type_caster/connection.rb
activerecord-5.1.5.rc1 lib/active_record/type_caster/connection.rb
activerecord-5.1.4 lib/active_record/type_caster/connection.rb
activerecord-5.1.4.rc1 lib/active_record/type_caster/connection.rb
activerecord-5.1.3 lib/active_record/type_caster/connection.rb
activerecord-5.1.3.rc3 lib/active_record/type_caster/connection.rb
activerecord-5.1.3.rc2 lib/active_record/type_caster/connection.rb
activerecord-5.1.3.rc1 lib/active_record/type_caster/connection.rb
activerecord-5.1.2 lib/active_record/type_caster/connection.rb
activerecord-5.1.2.rc1 lib/active_record/type_caster/connection.rb
activerecord-5.1.1 lib/active_record/type_caster/connection.rb
activerecord-5.1.0 lib/active_record/type_caster/connection.rb
activerecord-5.1.0.rc2 lib/active_record/type_caster/connection.rb
activerecord-5.1.0.rc1 lib/active_record/type_caster/connection.rb
activerecord-5.1.0.beta1 lib/active_record/type_caster/connection.rb