Class: ActiveType::TypeCaster::NativeCasters::DelegateToType

Inherits:
Object
  • Object
show all
Defined in:
lib/active_type/type_caster.rb

Overview

Adapter for Rails 4.2+. In these versions, casting logic lives in subclasses of ActiveRecord::Type::Value

Instance Method Summary collapse

Constructor Details

#initialize(type, connection) ⇒ DelegateToType

Returns a new instance of DelegateToType.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/active_type/type_caster.rb', line 67

def initialize(type, connection)
  # The specified type (e.g. "string") may not necessary match the
  # native type ("varchar") expected by the connection adapter.
  # PostgreSQL is one of these. Perform a translation if the adapter
  # supports it (but don't turn a mysql boolean into a tinyint).
  if !type.nil? && !(type == :boolean) && connection.respond_to?(:native_database_types)
    native_type = connection.native_database_types[type.to_sym]
    if native_type && native_type[:name]
      type = native_type[:name]
    else
      # unknown type, we just dont cast
      type = nil
    end
  end
  @active_record_type = connection.lookup_cast_type(type)
end

Instance Method Details

#type_cast_from_user(value) ⇒ Object



84
85
86
# File 'lib/active_type/type_caster.rb', line 84

def type_cast_from_user(value)
  @active_record_type.type_cast_from_user(value)
end