public
Description: Rails plugin to allow allow particular datetime attributes to also be treated as booleans
Homepage:
Clone URL: git://github.com/rubaidh/timestamped_booleans.git
mconnell (author)
Wed Apr 15 07:24:31 -0700 2009
commit  3de647d6f1f581e9ff02eaa80a0eb8789e522707
tree    3b128de1b156a4d339925a01b49b3f885a434a93
parent  49c36436b0f232d893536d5d4262728974ad307b
name age message
file .gitignore Thu Apr 10 01:25:14 -0700 2008 Ignore generated rdoc, if somebody happens to r... [mathie]
file MIT-LICENSE Wed Apr 15 07:24:31 -0700 2009 Bump copyright year [mconnell]
file README Wed Apr 15 07:24:31 -0700 2009 Bump copyright year [mconnell]
file Rakefile Wed Apr 09 23:53:04 -0700 2008 The results of script/generate plugin Timestamp... [mathie]
file init.rb Thu Apr 10 01:19:33 -0700 2008 Initial implementation of timestamped_booleans ... [mathie]
directory lib/ Thu Apr 10 10:07:38 -0700 2008 Create the named scopes too. I think those SQL... [mathie]
directory test/ Thu Apr 10 10:07:38 -0700 2008 Create the named scopes too. I think those SQL... [mathie]
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