Repository URL to install this package:
Version:
0.1.2 ▾
|
module Eventful
class Event < ActiveRecord::Base
def self.inherited(base)
super
base.acts_as_taggable
end
default_scope :order => :start_at
extend ::Montage::ActiveRecord::ClassMethods
montage :key
extend FriendlyId
friendly_id :title, :use => :slugged
pubdraft
attr_accessible :title, :body, :start_at, :end_at, :tag_list
scope :by_year, lambda { |year|
year = DateTime.new(year, 1, 1)
where('start_at BETWEEN ? AND ?',
year.beginning_of_year,
year.end_of_year)
}
scope :by_month, lambda { |month, year|
month = DateTime.new(year, month, 1)
where('start_at BETWEEN ? AND ?',
month.beginning_of_month,
month.end_of_month)
}
scope :by_day, lambda { |*args|
day = if args.count == 3
# day, month, year
# were given separately
d, m, y = args[0], args[1], args[2]
DateTime.new(y, m, d)
else
# date object was given
args[0]
end
where('start_at BETWEEN ? AND ?',
day.beginning_of_day,
day.end_of_day)
}
scope :upcoming, lambda {
where('start_at >= ?', DateTime.now)
}
scope :current, lambda {
where('start_at <= :time AND end_at >= :time',
:time => DateTime.now)
}
scope :past, lambda {
where('end_at <= ?', DateTime.now)
}
end
end