Sha256: 794a6e1faf49466ead3e532cca7f286e19d2446aaadf411881d83af2bedb48aa
Contents?: true
Size: 1.06 KB
Versions: 19
Compression:
Stored size: 1.06 KB
Contents
# Mongoid serialization support for Timespan type. module Mongoid module Fields class Timespan include Mongoid::Fields::Serializable def self.instantiate(name, options = {}) super end # Deserialize a Timespan given the hash stored by Mongodb # # @param [Hash] Timespan as hash # @return [Timespan] deserialized Timespan def deserialize(hash) return if !hash ::Timespan.new :from => from(hash), :to => to(hash) end # Serialize a Timespan or a Hash (with Timespan units) or a Duration in some form to # a BSON serializable type. # # @param [Timespan, Hash, Integer, String] value # @return [Hash] Timespan in seconds def serialize(value) return if value.blank? timespan = case value when ::Timespan value else ::Timespan.new(value) end {:from => serialize_time(timespan.start_time), :to => serialize_time(timespan.end_time.to_i), :duration => timespan.duration.total } end end end end
Version data entries
19 entries across 19 versions & 1 rubygems