Module: Mongoid::Fields::Timespan::Methods
- Included in:
- Mongoid::Fields::Timespan, Mongoid::Fields::Timespan
- Defined in:
- lib/timespan/mongoid.rb
Overview
protected
Instance Method Summary collapse
- #asap(hash) ⇒ Object
- #deserialize_time(millisecs) ⇒ Object
- #from(hash) ⇒ Object
- #serialize_time(time) ⇒ Object
- #to(hash) ⇒ Object
Instance Method Details
#asap(hash) ⇒ Object
42 43 44 45 46 |
# File 'lib/timespan/mongoid.rb', line 42 def asap hash asap_value = hash['asap'] || hash[:asap] raise ArgumentError, ":asap is nil, #{hash.inspect}" if ![true, false, nil].include? asap_value asap_value end |
#deserialize_time(millisecs) ⇒ Object
53 54 55 56 |
# File 'lib/timespan/mongoid.rb', line 53 def deserialize_time millisecs raise ArgumentError, "Can't deserialize time from nil" if millisecs.nil? Time.at millisecs end |
#from(hash) ⇒ Object
30 31 32 33 34 |
# File 'lib/timespan/mongoid.rb', line 30 def from hash from_value = hash['from'] || hash[:from] raise ArgumentError, ":from is nil, #{hash.inspect}" if from_value.nil? deserialize_time from_value end |
#serialize_time(time) ⇒ Object
48 49 50 51 |
# File 'lib/timespan/mongoid.rb', line 48 def serialize_time time raise ArgumentError, "Can't serialize time from nil" if time.nil? time.to_i end |
#to(hash) ⇒ Object
36 37 38 39 40 |
# File 'lib/timespan/mongoid.rb', line 36 def to hash to_value = hash['to'] || hash[:to] raise ArgumentError, ":to is nil, #{hash.inspect}" if to_value.nil? deserialize_time to_value end |