Class: CouchPotato::Persistence::TypeCaster
- Inherits:
-
Object
- Object
- CouchPotato::Persistence::TypeCaster
- Defined in:
- lib/couch_potato/persistence/type_caster.rb
Overview
:nodoc:
Constant Summary collapse
- NUMBER_REGEX =
/-?\d*\.?\d*/.freeze
Instance Method Summary collapse
Instance Method Details
#cast(value, type) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/couch_potato/persistence/type_caster.rb', line 9 def cast(value, type) if type == :boolean cast_boolean(value) elsif type.instance_of?(Array) nested_type = type.first value&.map { |val| cast_native(val, nested_type) } else cast_native(value, type) end end |
#cast_back(value) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/couch_potato/persistence/type_caster.rb', line 20 def cast_back(value) if value.is_a?(Time) value.utc else value end end |