Class: SqliteCrypto::Type::Base

Inherits:
ActiveRecord::Type::String
  • Object
show all
Defined in:
lib/sqlite_crypto/type/base.rb

Direct Known Subclasses

ULID, Uuid

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sqlite_crypto/type/base.rb', line 11

def cast(value)
  return if value.nil?
  return value if value.is_a?(String) && valid?(value)

  if value.respond_to?(:to_s)
    str = value.to_s
    return str if valid?(str)
  end

  raise ArgumentError, "Invalid #{type.upcase}: #{value.inspect}"
end

#changed_in_place?(raw_old_value, new_value) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sqlite_crypto/type/base.rb', line 27

def changed_in_place?(raw_old_value, new_value)
  cast(raw_old_value) != cast(new_value)
end

#deserialize(value) ⇒ Object



6
7
8
9
# File 'lib/sqlite_crypto/type/base.rb', line 6

def deserialize(value)
  return if value.nil?
  cast(value)
end

#serialize(value) ⇒ Object



23
24
25
# File 'lib/sqlite_crypto/type/base.rb', line 23

def serialize(value)
  cast(value)
end