Project

transient

0.0
No commit activity in last 3 years
No release in over 3 years
Provides an API for making any ActiveRecord object transient.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.0.0
 Project Readme

transient¶ ↑

github.com/midas/transient

DESCRIPTION¶ ↑

Provides an API for making any ActiveRecord object transient.

FEATURES¶ ↑

  • Convenience methods for transient objects, ie. current?, expired?, expire!, etc.

  • Callbacks for expiring current ‘active’ record prior to creating new one where certain configured fields match. See the Transient::ActiveRecordExtensions::InstanceMethods docs for more information.

  • A callback to populate the expiring at field of a new record with DateTime.now unless a value was explicitly specified for the effective at field.

  • Automatically adds a presence validation for effective_at to the model.

REQUIREMENTS¶ ↑

  • Rails >= 3.0.0

INSTALL¶ ↑

gem sources -a http://gemcutter.org
sudo gem install transient

INSTALL FOR RAILS¶ ↑

Add to Gemfile:

gem "transient"

Run:

bundle install

USAGE¶ ↑

Add the transient fields to your model:

def self.up
  add_column :users, :effective_at, :datetime, :null => false
  add_column :users, :expiring_at, :datetime
end

Call the macro from your ActiveRecord descendant class:

class User < ActiveRecord::Base
  acts_as_transient
end

Now you can use all of the convenience methods, expired?, current?, expire!, etc. See the InstanceMethods docs for more information.

Call the macro with a list of fields to use to lookup the current active record and expire it before saving the new one:

class ContactNumber < ActiveRecord::Base
  acts_as_transient :single_active => %w(location user_id)
end

This will try to find an existing contact number record where the location and user_id match the record being saved and expire the existing record before saving the new record.

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

LICENSE¶ ↑

Copyright © 2009 C. Jason Harrelson (midas)

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE