fast_timestamp 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,17 +1,28 @@
1
1
  = fast_timestamp
2
2
 
3
- Description goes here.
3
+ == Suggested Timestamp model
4
4
 
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but
13
- bump version in a commit by itself I can ignore when I pull)
14
- * Send me a pull request. Bonus points for topic branches.
5
+ class Timestamp < ActiveRecord::Base
6
+ index [:timestampable_id, :timestampable_type, :key] # for cache-money only
7
+ index :id # for cache-money only
8
+ belongs_to :timestampable, :polymorphic => true
9
+ validates_presence_of :key, :timestampable_id, :timestampable_type
10
+ validates_uniqueness_of :key, :scope => [ :timestampable_id, :timestampable_type ]
11
+ end
12
+
13
+ == Suggested Timestamp migration
14
+
15
+ create_table "timestamps", :force => true do |t|
16
+ t.integer "timestampable_id"
17
+ t.string "timestampable_type"
18
+ t.string "key"
19
+ t.datetime "stamped_at"
20
+ t.datetime "created_at"
21
+ t.datetime "updated_at"
22
+ end
23
+
24
+ add_index "timestamps", ["timestampable_id", "timestampable_type", "key"], :name => "index_timestamps_on_t_id_and_t_type_and_key"
25
+ add_index "timestamps", ["timestampable_id", "timestampable_type"], :name => "index_timestamps_on_timestampable_id_and_timestampable_type"
15
26
 
16
27
  == Copyright
17
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fast_timestamp}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Seamus Abshere"]
@@ -5,14 +5,27 @@ module FastTimestamp
5
5
  end
6
6
 
7
7
  def timestamp!(key)
8
+ raise "Can't timestamp new records" if new_record?
8
9
  transaction do
9
10
  t = ::Timestamp.find_or_create_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
10
11
  t.update_attribute :stamped_at, Time.zone.now
11
12
  end
12
13
  end
14
+
15
+ def untimestamp!(key)
16
+ if t = ::Timestamp.find_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s)
17
+ t.destroy
18
+ end
19
+ end
13
20
 
14
21
  def timestamped?(key)
15
- ::Timestamp.find_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s).present?
22
+ raise "Can't check timestamps on new record" if new_record?
23
+ ::Timestamp.exists? :timestampable_type => self.class.base_class.name, :timestampable_id => id, :key => key.to_s
24
+ end
25
+
26
+ # returns a Time object
27
+ def timestamp_for(key)
28
+ ::Timestamp.find_by_timestampable_type_and_timestampable_id_and_key(self.class.base_class.name, id, key.to_s).read_attribute :stamped_at
16
29
  end
17
30
 
18
31
  def fast_destroy_timestamps
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_timestamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere