seamusabshere-has_timestamps 1.0 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -5,6 +5,19 @@ Lets you timestamp models, like if you want to fake a CRM.
5
5
 
6
6
  Note: it doesn't save objects automatically, so you have to run a "user.save" (etc.) when you're done timestamping.
7
7
 
8
+ Installation
9
+ ============
10
+
11
+ You should be able to run this as a plugin or as a gem.
12
+
13
+ For environment.rb:
14
+
15
+ config.gem 'seamusabshere-has_timestamps', :lib => 'has_timestamps', :source => 'http://gems.github.com'
16
+
17
+ Then be sure to:
18
+
19
+ rake gems:install
20
+
8
21
  Example
9
22
  =======
10
23
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "has_timestamps"
3
- s.version = "1.0"
3
+ s.version = "1.1"
4
4
  s.date = "2008-12-29"
5
5
  s.summary = "Rails plugin to add named timestamps to ActiveRecord models."
6
6
  s.email = "seamus@abshere.net"
@@ -10,15 +10,12 @@ Gem::Specification.new do |s|
10
10
  s.authors = "Seamus Abshere"
11
11
  s.files = [
12
12
  "has_timestamps.gemspec",
13
- "init.rb",
14
- "install.rb",
15
13
  "lib/has_timestamps.rb",
16
14
  "lib/timestamp.rb",
17
15
  "MIT-LICENSE",
18
16
  "Rakefile",
19
17
  "README",
20
18
  "tasks/has_timestamps_tasks.rake",
21
- "uninstall.rb"
22
19
  ]
23
20
  s.test_files = [
24
21
  "test/has_timestamps_test.rb",
@@ -1,58 +1,56 @@
1
- module ActiveRecord #:nodoc:
2
- module Acts #:nodoc:
3
- module HasTimestamps
4
- def self.included(base) #:nodoc:
5
- base.extend(ClassMethods)
6
- end
1
+ module HasTimestamps
2
+ def self.included(base) #:nodoc:
3
+ base.extend(ClassMethods)
4
+ end
7
5
 
8
- module ClassMethods
9
- def has_timestamps(opts = {})
10
- class_eval do
11
- def save_or_destroy_timestamps
12
- timestamps.each do |timestamp|
13
- if timestamp.stamped_at.acts_like?(:time) or timestamp.stamped_at.is_a?(Date) or timestamp.stamped_at.is_a?(DateTime)
14
- timestamp.save
15
- elsif !timestamp.new_record?
16
- timestamp.destroy
17
- end
18
- end
19
- end
20
- after_save :save_or_destroy_timestamps
21
-
22
- def timestamp!(key)
23
- timestamps[key.to_s] = Time.now
24
- end
25
-
26
- def timestamped?(key)
27
- !timestamps[key.to_s].blank?
6
+ module ClassMethods
7
+ def has_timestamps(opts = {})
8
+ class_eval do
9
+ def save_or_destroy_timestamps
10
+ timestamps.each do |timestamp|
11
+ if timestamp.stamped_at.acts_like?(:time) or timestamp.stamped_at.is_a?(Date) or timestamp.stamped_at.is_a?(DateTime)
12
+ timestamp.save
13
+ elsif !timestamp.new_record?
14
+ timestamp.destroy
28
15
  end
29
16
  end
17
+ end
18
+ after_save :save_or_destroy_timestamps
19
+
20
+ def timestamp!(key)
21
+ timestamps[key.to_s] = Time.now
22
+ end
23
+
24
+ def timestamped?(key)
25
+ !timestamps[key.to_s].blank?
26
+ end
27
+ end
30
28
 
31
- has_many :timestamps, opts.merge(:as => :timestampable) do
32
- def [](key)
33
- fetch_timestamp(key).stamped_at
34
- end
29
+ has_many :timestamps, opts.merge(:as => :timestampable) do
30
+ def [](key)
31
+ fetch_timestamp(key).stamped_at
32
+ end
35
33
 
36
- def []=(key, stamped_at)
37
- fetch_timestamp(key).stamped_at = stamped_at
38
- end
34
+ def []=(key, stamped_at)
35
+ fetch_timestamp(key).stamped_at = stamped_at
36
+ end
39
37
 
40
- def find_by_key(key)
41
- proxy_owner.timestamps.to_a.find { |timestamp| timestamp.key == key.to_s }
42
- end
38
+ def find_by_key(key)
39
+ proxy_owner.timestamps.to_a.find { |timestamp| timestamp.key == key.to_s }
40
+ end
43
41
 
44
- private
42
+ private
45
43
 
46
- def fetch_timestamp(key)
47
- find_by_key(key) || build_timestamp(key)
48
- end
44
+ def fetch_timestamp(key)
45
+ find_by_key(key) || build_timestamp(key)
46
+ end
49
47
 
50
- def build_timestamp(key)
51
- build(:key => key.to_s)
52
- end
53
- end
48
+ def build_timestamp(key)
49
+ build(:key => key.to_s)
54
50
  end
55
51
  end
56
52
  end
57
53
  end
58
54
  end
55
+
56
+ ActiveRecord::Base.class_eval { include HasTimestamps }
data/test/test_helper.rb CHANGED
@@ -27,7 +27,8 @@ module HasTimestampsTest
27
27
  require 'rubygems' rescue LoadError
28
28
 
29
29
  require 'test/spec'
30
- require File.join(PLUGIN_ROOT, 'init')
30
+ require 'timestamp'
31
+ require 'has_timestamps'
31
32
  end
32
33
 
33
34
  def self.configure_database
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seamusabshere-has_timestamps
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -23,15 +23,12 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - has_timestamps.gemspec
26
- - init.rb
27
- - install.rb
28
26
  - lib/has_timestamps.rb
29
27
  - lib/timestamp.rb
30
28
  - MIT-LICENSE
31
29
  - Rakefile
32
30
  - README
33
31
  - tasks/has_timestamps_tasks.rake
34
- - uninstall.rb
35
32
  has_rdoc: false
36
33
  homepage: http://github.com/seamusabshere/has_timestamps
37
34
  post_install_message:
data/init.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'has_timestamps'
2
- ActiveRecord::Base.send(:include, ActiveRecord::Acts::HasTimestamps)
3
-
4
- require File.dirname(__FILE__) + '/lib/timestamp'
data/install.rb DELETED
@@ -1 +0,0 @@
1
- # Install hook code here
data/uninstall.rb DELETED
@@ -1 +0,0 @@
1
- # Uninstall hook code here