module
RemiLib::RSConf::HashValueConverter(Converter)
Overview
Converter to be used with RemiLib::RSConf::Serializable
to serialize the values of a Hash(String, V) with the custom converter.
require "libremiliacr"
alias RSConf = RemiLib::RSConf
class TimestampHash
include RSConf::Serializable
@[RSConf::Field(converter: RSConf::HashValueConverter(Time::EpochConverter))]
property birthdays : Hash(String, Time)
end
timestamp = TimestampHash.fromRsconf(%|{"birthdays":{"foo":1459859781,"bar":1567628762}}|)
puts timestamp.birthdays # => {"foo" => 2016-04-05 12:36:21 UTC, "bar" => 2019-09-04 20:26:02 UTC}
puts timestamp.toRsconf
RemiLib::RSConf::HashValueConverter.new should be used if the nested
converter is also an instance instead of a type.
require "libremiliacr"
alias RSConf = RemiLib::RSConf
class TimestampHash
include RSConf::Serializable
@[RSConf::Field(converter: RSConf::HashValueConverter.new(Time::Format.new("%b %-d, %Y")))]
property birthdays : Hash(String, Time)
end
timestamp = TimestampHash.fromRsconf(%|{"birthdays":{"foo":"Apr 5, 2016","bar":"Sep 4, 2019"}}|)
puts timestamp.birthdays # => {"foo" => 2016-04-05 00:00:00 UTC, "bar" => 2019-09-04 00:00:00 UTC}
puts timestamp.toRsconf
This implies that RemiLib::RSConf::HashValueConverter(T) and
RemiLib::RSConf::HashValueConverter(T.class).new(T) perform the same
serializations.