Giter VIP home page Giter VIP logo

transient's Introduction

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

transient's People

Stargazers

Omar avatar Jason Harrelson avatar Minofare avatar

Watchers

Minofare avatar Jason Harrelson avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.