This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit 3de647d6f1f581e9ff02eaa80a0eb8789e522707
tree 3b128de1b156a4d339925a01b49b3f885a434a93
parent 49c36436b0f232d893536d5d4262728974ad307b
tree 3b128de1b156a4d339925a01b49b3f885a434a93
parent 49c36436b0f232d893536d5d4262728974ad307b
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Thu Apr 10 01:25:14 -0700 2008 | |
| |
MIT-LICENSE | Wed Apr 15 07:24:31 -0700 2009 | |
| |
README | Wed Apr 15 07:24:31 -0700 2009 | |
| |
Rakefile | Wed Apr 09 23:53:04 -0700 2008 | |
| |
init.rb | Thu Apr 10 01:19:33 -0700 2008 | |
| |
lib/ | Thu Apr 10 10:07:38 -0700 2008 | |
| |
test/ | Thu Apr 10 10:07:38 -0700 2008 |
README
= Timestamped Booleans
== Introduction
Sometimes you have an attribute on a model that stores a time stamp in the
database, because sometimes you want to know *when* an event happens. But
mostly what you want to know is whether it has actually happened at all or
not. This plugin gives us an easy way to specify that, rather than having to
explicitly write methods to implement the boolean methods on top of the
datetime attribute methods.
Tested to work with Rails 2.3
== Example
Let's say I have a `Book` model which records when a book has been published
in the `published_at` field. But for the most part, I'm just interested in
whether the book has been published already or not. We can set up the time
stamped boolean in the model as follows:
class Book < ActiveRecord::Base
timestamped_boolean :published_at
end
Now, in addition to the `published_at` and `published_at=` methods to
manipulate the attribute, we have `published?` and `published=` which treats
the field as a boolean. Let's see how that works:
irb(main):001:0> b = Book.new
=> #<Book id: nil, published_at: nil, created_at: nil, updated_at: nil>
irb(main):002:0> b.published?
=> false
irb(main):003:0> b.published = true
=> true
irb(main):004:0> b.published?
=> true
irb(main):005:0> b.published_at
=> Thu, 10 Apr 2008 08:06:43 IST +01:00
irb(main):006:0> b.published = false
=> false
irb(main):007:0> b.published_at
=> nil
irb(main):008:0> b.published?
=> false
== TODO
* Parameterize the value we set so that it isn't necessarily +Time.now+. I
suspect some people will want to specify a different value, probably as a
lambda. However, I don't need that functionality yet. :-)
Copyright (c) 2008-2009 Rubaidh Ltd, released under the MIT license







