Class: Typed::HashSerializer
- Inherits:
-
Serializer
- Object
- Serializer
- Typed::HashSerializer
- Defined in:
- lib/typed/hash_serializer.rb
Constant Summary collapse
- InputHash =
T.type_alias { T::Hash[T.any(Symbol, String), T.untyped] }
- Input =
type_member { {fixed: InputHash} }
- Output =
type_member { {fixed: Params} }
Constants inherited from Serializer
Serializer::DeserializeResult, Serializer::Params
Instance Attribute Summary collapse
-
#should_serialize_values ⇒ Object
readonly
Returns the value of attribute should_serialize_values.
Attributes inherited from Serializer
Instance Method Summary collapse
- #deserialize(source) ⇒ Object
-
#initialize(schema:, should_serialize_values: false) ⇒ HashSerializer
constructor
A new instance of HashSerializer.
- #serialize(struct) ⇒ Object
Constructor Details
#initialize(schema:, should_serialize_values: false) ⇒ HashSerializer
Returns a new instance of HashSerializer.
13 14 15 16 17 |
# File 'lib/typed/hash_serializer.rb', line 13 def initialize(schema:, should_serialize_values: false) @should_serialize_values = should_serialize_values super(schema: schema) end |
Instance Attribute Details
#should_serialize_values ⇒ Object (readonly)
Returns the value of attribute should_serialize_values.
10 11 12 |
# File 'lib/typed/hash_serializer.rb', line 10 def should_serialize_values @should_serialize_values end |
Instance Method Details
#deserialize(source) ⇒ Object
20 21 22 |
# File 'lib/typed/hash_serializer.rb', line 20 def deserialize(source) deserialize_from_creation_params(HashTransformer.symbolize_keys(source)) end |
#serialize(struct) ⇒ Object
25 26 27 28 29 |
# File 'lib/typed/hash_serializer.rb', line 25 def serialize(struct) return Failure.new(SerializeError.new("'#{struct.class}' cannot be serialized to target type of '#{schema.target}'.")) if struct.class != schema.target Success.new(serialize_from_struct(struct:, should_serialize_values:)) end |