"Schedulability" to your models, as simple as 1, 2,
schedulable
Just install.
$ script/plugin install git://github.com/cementhorses/schedulable.git
Calling schedulable
automatically hooks a few methods to a published_at
column:
scheduled?
(true
if the item is scheduled to be published but isn't yet)published?
(true
if the item is published)
The real power is when expiration is a question
schedulable :end => :archived_at
or
schedulable :published_at, :archived_at
does a little more:
scheduled? :archived_at
(true
ifarchived_at
is set in the future)archived?
(true
if the item has been archived)
with a note:
published?
returnsfalse
whenarchived?
returnstrue
.
It's all semantic sugar:
schedulable :activated_at, :terminated_at, :end_required => true
therefore creates:
activated?
terminated?
And that last option? It just adds a validation requiring the :end
to be set
if the :start
is.
We have your other validations taken care of, too. We're just more comfortable with things when they're chronological.
named_scope
support means a few extra methods.
class NewsItem < ActiveRecord::Base
schedulable :published_at, :archived_at
end
Now you can scope it out:
NewsItem.scheduled
returns news items scheduled to be publishedNewsItem.published
returns published news itemsNewsItem.archived
returns archived news items
Copyright (c) 2008 Cement Horses, released under the MIT license.