module FieldMaskedModel::AttributeConverter
Constants
- NULLABLE_TYPES
Public Class Methods
convert(value)
click to toggle source
# File lib/field_masked_model/attribute_converter.rb, line 19 def convert(value) case value when Google::Protobuf::Timestamp timestamp_to_time(value) when *NULLABLE_TYPES value.value else # TODO(south37) Add conversion logic of other classes value end end
timestamp_to_time(timestamp)
click to toggle source
@param [Google::Protobuf::Timestamp] timestamp @return [Time, ActiveSupport::TimeWithZone]
# File lib/field_masked_model/attribute_converter.rb, line 33 def timestamp_to_time(timestamp) v = timestamp.nanos * (10 ** -9) + timestamp.seconds if Time.respond_to?(:zone) && Time.zone.respond_to?(:at) # Use ActiveSupport::TimeWithZone when it is available. Time.zone.at(v) else Time.at(v) end end