Class: SqliteCrypto::Type::Base
- Inherits:
-
ActiveRecord::Type::String
- Object
- ActiveRecord::Type::String
- SqliteCrypto::Type::Base
- Defined in:
- lib/sqlite_crypto/type/base.rb
Instance Method Summary collapse
- #cast(value) ⇒ Object
- #changed_in_place?(raw_old_value, new_value) ⇒ Boolean
- #deserialize(value) ⇒ Object
- #serialize(value) ⇒ Object
Instance Method Details
#cast(value) ⇒ Object
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
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 |