Class: Cyrel::Types::HashType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Cyrel::Types::HashType
- Defined in:
- lib/cyrel/types/hash_type.rb
Instance Method Summary collapse
- #cast(value) ⇒ Object
-
#serialize(value) ⇒ Object
Serialize as a plain Hash (e.g., for JSON output); symbols are fine.
Instance Method Details
#cast(value) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/cyrel/types/hash_type.rb', line 9 def cast(value) case value when nil then ActiveSupport::HashWithIndifferentAccess.new when Hash then value.with_indifferent_access else value.respond_to?(:to_h) ? value.to_h.with_indifferent_access : {} end end |
#serialize(value) ⇒ Object
Serialize as a plain Hash (e.g., for JSON output); symbols are fine
19 |
# File 'lib/cyrel/types/hash_type.rb', line 19 def serialize(value) = cast(value) |