Sha256: 7ebb30cf47b628987770229b4c3d412fa5202333b833b195ac7e7b101b1b6bd0

Contents?: true

Size: 912 Bytes

Versions: 34

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

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

34 entries across 34 versions & 4 rubygems

Version Path
activerecord-5.2.8.1 lib/active_record/type_caster/connection.rb
activerecord-5.2.8 lib/active_record/type_caster/connection.rb
activerecord-5.2.7.1 lib/active_record/type_caster/connection.rb
activerecord-5.2.7 lib/active_record/type_caster/connection.rb
activerecord-5.2.6.3 lib/active_record/type_caster/connection.rb
activerecord-5.2.6.2 lib/active_record/type_caster/connection.rb
activerecord-5.2.6.1 lib/active_record/type_caster/connection.rb
activerecord-5.2.6 lib/active_record/type_caster/connection.rb
activerecord-5.2.4.6 lib/active_record/type_caster/connection.rb
activerecord-5.2.5 lib/active_record/type_caster/connection.rb
activerecord-5.2.4.5 lib/active_record/type_caster/connection.rb
activerecord-5.2.4.4 lib/active_record/type_caster/connection.rb
activerecord-5.2.4.3 lib/active_record/type_caster/connection.rb
activerecord-5.2.4.2 lib/active_record/type_caster/connection.rb
activerecord-5.2.4.1 lib/active_record/type_caster/connection.rb
activerecord-5.2.4 lib/active_record/type_caster/connection.rb
activerecord-5.2.4.rc1 lib/active_record/type_caster/connection.rb
spiral_form-0.1.1 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/type_caster/connection.rb
spiral_form-0.1.0 vendor/bundle/gems/activerecord-5.2.3/lib/active_record/type_caster/connection.rb
activerecord-5.2.3 lib/active_record/type_caster/connection.rb