class ActiveType::TypeCaster::NativeCasters::DelegateToRails5Type

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

Public Class Methods

new(type) click to toggle source
# File lib/active_type/type_caster.rb, line 109
def initialize(type)
  @active_record_type = lookup(type)
end

Public Instance Methods

type_cast_from_user(value) click to toggle source
# File lib/active_type/type_caster.rb, line 113
def type_cast_from_user(value)
  @active_record_type.cast(value)
end

Private Instance Methods

lookup(type) click to toggle source
# File lib/active_type/type_caster.rb, line 119
def lookup(type)
  if type.respond_to?(:cast)
    type
  else
    ActiveRecord::Type.lookup(type, adapter: nil)
  end
rescue ::ArgumentError
  ActiveRecord::Type::Value.new
end