Sha256: e49bc97eb000394ddcda509dc5f2c97668cb374fb24c9a24c66985a02e22654c

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

HasTimestamps
=================

Lets you timestamp models, like if you want to fake a CRM.

Note: it doesn't save objects automatically, so you have to run a "user.save" (etc.) when you're done timestamping.

Installation
============

You should be able to run this as a plugin or as a gem.

For environment.rb:

config.gem 'seamusabshere-has_timestamps', :lib => 'has_timestamps', :source => 'http://gems.github.com'

Then be sure to:

rake gems:install

Example
=======

class CreateTimestamps < ActiveRecord::Migration
  def self.up
    create_table(:timestamps) do |t|
      t.integer   :timestampable_id
      t.string    :timestampable_type
      t.string    :key
      t.datetime  :stamped_at
      t.timestamps
    end
  end

  def self.down
    drop_table(:timestamps)
  end
end

then...

class User < ActiveRecord::Base
  has_timestamps
end

>> user.timestamps
=> []
>> user.timestamp!(:hailed)
=> Wed Dec 10 15:11:52 -0500 2008
>> user.timestamps
=> [#<Timestamp id: nil, timestampable_id: 14, timestampable_type: "User", key: "hailed", stamped_at: "2008-12-10 15:11:52", created_at: nil, updated_at: nil>]
>> user.timestamped?(:hailed)
=> true
>> user.save
=> true
>> user.timestamped?(:saluted)
=> false
>> user.timestamp!(:saluted)
=> Wed Dec 10 15:12:28 -0500 2008
>> user.timestamped?(:saluted)
=> true
>> user.timestamps[:saluted]
=> Wed Dec 10 15:12:28 -0500 2008
>> user.timestamps[:hailed]
=> Wed Dec 10 15:11:52 -0500 2008

Credits
=======

Thanks to Fingertips for inspiration.

Copyright (c) 2008 Seamus Abshere, released under the MIT license.

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
seamusabshere-has_timestamps-1.1 README
seamusabshere-has_timestamps-1.2 README
seamusabshere-has_timestamps-1.3 README