Skip to content

Add ability to use datetime fields as boolean attributes to ActiveRecord models

License

Notifications You must be signed in to change notification settings

daikini/event_attribute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EventAttribute
==============

EventAttribute allows you to turn your date/datetime columns in to boolean attributes.
Idea for this was taken from http://jamis.jamisbuck.org/articles/2005/12/14/two-tips-for-working-with-databases-in-rails


Example
=======

  class Referral < ActiveRecord::Base
    event_attribute :applied_at, :attribute => 'pending', :nil_equals => true
    event_attribute :subscribed_on
  end

  referral = Referral.create(:applied_at => Time.now)
  referral.pending?           # => false
  referral.subscribed?        # => false
  
  referral.pending = true
  referral.applied_at         # => nil
  referral.pending?           # => true
  
  referral.subscribed = true
  referral.subscribed_on      # => Time.now
  referral.subscribed?        # => true
  
  
  # Dynamic finders are also added so that you can search on these boolean attributes.
  Referral.find_all_by_pending(true)  # => [Referral objects]

  # or
  Referral.find_by_name_and_pending_and_subscribed('John Smith', false, true)  # => Referral object

Copyright (c) 2007 Jonathan Younger, released under the MIT license

About

Add ability to use datetime fields as boolean attributes to ActiveRecord models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages