Sha256: c171f1254d5f6b4cceadc44e82fc78c57464343459d06ce6468dd4e63347a4db

Contents?: true

Size: 817 Bytes

Versions: 98

Compression:

Stored size: 817 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(attr_name, value)
        type = type_for_attribute(attr_name)
        type.serialize(value)
      end

      def type_for_attribute(attr_name)
        schema_cache = connection.schema_cache

        if schema_cache.data_source_exists?(table_name)
          column = schema_cache.columns_hash(table_name)[attr_name.to_s]
          type = connection.lookup_cast_type_from_column(column) if column
        end

        type || Type.default_value
      end

      delegate :connection, to: :@klass, private: true

      private
        attr_reader :table_name
    end
  end
end

Version data entries

98 entries across 93 versions & 10 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.8.7/lib/active_record/type_caster/connection.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/type_caster/connection.rb
activerecord-7.1.5.1 lib/active_record/type_caster/connection.rb
activerecord-7.0.8.7 lib/active_record/type_caster/connection.rb
activerecord-7.1.5 lib/active_record/type_caster/connection.rb
activerecord-7.1.4.2 lib/active_record/type_caster/connection.rb
activerecord-7.0.8.6 lib/active_record/type_caster/connection.rb
activerecord-6.1.7.10 lib/active_record/type_caster/connection.rb
activerecord-6.1.7.9 lib/active_record/type_caster/connection.rb
activerecord-7.1.4.1 lib/active_record/type_caster/connection.rb
activerecord-7.0.8.5 lib/active_record/type_caster/connection.rb
activerecord-7.1.4 lib/active_record/type_caster/connection.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8.4/lib/active_record/type_caster/connection.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activerecord-7.1.3.4/lib/active_record/type_caster/connection.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/type_caster/connection.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/type_caster/connection.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activerecord-7.0.5.1/lib/active_record/type_caster/connection.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activerecord-7.1.3.4/lib/active_record/type_caster/connection.rb
activerecord-7.1.3.4 lib/active_record/type_caster/connection.rb
activerecord-7.0.8.4 lib/active_record/type_caster/connection.rb