Sha256: ea03f40b6658504390f6ceab9cba0b2beca0e691789111804cb8a410fae3226c

Contents?: true

Size: 710 Bytes

Versions: 9

Compression:

Stored size: 710 Bytes

Contents

require 'timespan/mongoid/models/time_period'

class Account
  include Mongoid::Document
  include Mongoid::Timespanned

  field :name
  field :period, :type => ::Timespan, :between => true

  timespan_methods :period

  embeds_one :time_period
  
  timespan_container_delegates :time_period, :dates, :all

  def self.create_it! duration, flex = nil
    acc = self.new period: ::Timespan.new(duration: duration), time_period: ::TimePeriod.new
    acc.time_period.dates_duration = 1.day
    acc.time_period.flex = flex if flex
    acc
  end

#   def to_s
#     %Q{
# name: #{name}
# }
#   end

  def self.between from, to
    Account.where(:'period.from'.gt => from.to_i, :'period.to'.lte => to.to_i)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
timespan-0.6.0 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.9 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.7 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.6.1 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.6 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.5 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.4 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.3 spec/timespan/mongoid/models/account_3x.rb
timespan-0.5.2 spec/timespan/mongoid/models/account_3x.rb