dm-timestamps 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → History.rdoc} +4 -0
- data/Manifest.txt +2 -2
- data/{README.txt → README.rdoc} +0 -0
- data/Rakefile +2 -3
- data/lib/dm-timestamps.rb +23 -18
- data/lib/dm-timestamps/version.rb +1 -1
- data/spec/integration/timestamps_spec.rb +39 -20
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +13 -4
- data/tasks/install.rb +1 -1
- data/tasks/spec.rb +4 -4
- metadata +14 -21
data/Manifest.txt
CHANGED
data/{README.txt → README.rdoc}
RENAMED
File without changes
|
data/Rakefile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'pathname'
|
2
|
-
require 'rubygems'
|
3
2
|
|
4
3
|
ROOT = Pathname(__FILE__).dirname.expand_path
|
5
4
|
JRUBY = RUBY_PLATFORM =~ /java/
|
@@ -14,10 +13,10 @@ GEM_NAME = 'dm-timestamps'
|
|
14
13
|
GEM_VERSION = DataMapper::Timestamps::VERSION
|
15
14
|
GEM_DEPENDENCIES = [['dm-core', GEM_VERSION]]
|
16
15
|
GEM_CLEAN = %w[ log pkg coverage ]
|
17
|
-
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.
|
16
|
+
GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.rdoc LICENSE TODO History.rdoc ] }
|
18
17
|
|
19
18
|
PROJECT_NAME = 'datamapper'
|
20
|
-
PROJECT_URL = "http://github.com/
|
19
|
+
PROJECT_URL = "http://github.com/datamapper/dm-more/tree/master/#{GEM_NAME}"
|
21
20
|
PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin for magical timestamps'
|
22
21
|
|
23
22
|
[ ROOT, ROOT.parent ].each do |dir|
|
data/lib/dm-timestamps.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
gem 'dm-core', '0.9.11'
|
4
|
-
require 'dm-core'
|
5
|
-
|
6
1
|
module DataMapper
|
7
|
-
module
|
8
|
-
Resource.append_inclusions self
|
9
|
-
|
2
|
+
module Timestamps
|
10
3
|
TIMESTAMP_PROPERTIES = {
|
11
|
-
:updated_at => [ DateTime, lambda { |r, p| DateTime.now
|
12
|
-
:updated_on => [ Date, lambda { |r, p| Date.today
|
13
|
-
:created_at => [ DateTime, lambda { |r, p| r.created_at || (DateTime.now if r.
|
14
|
-
:created_on => [ Date, lambda { |r, p| r.created_on || (Date.today if r.
|
4
|
+
:updated_at => [ DateTime, lambda { |r, p| DateTime.now } ],
|
5
|
+
:updated_on => [ Date, lambda { |r, p| Date.today } ],
|
6
|
+
:created_at => [ DateTime, lambda { |r, p| r.created_at || (DateTime.now if r.new?) } ],
|
7
|
+
:created_on => [ Date, lambda { |r, p| r.created_on || (Date.today if r.new?) } ],
|
15
8
|
}.freeze
|
16
9
|
|
17
10
|
def self.included(model)
|
18
|
-
model.before :
|
19
|
-
model.before :update, :set_timestamps
|
11
|
+
model.before :save, :set_timestamps_on_save
|
20
12
|
model.extend ClassMethods
|
21
13
|
end
|
22
14
|
|
15
|
+
# Saves the record with the updated_at/on attributes set to the current time.
|
16
|
+
def touch
|
17
|
+
set_timestamps
|
18
|
+
save
|
19
|
+
end
|
20
|
+
|
23
21
|
private
|
24
22
|
|
23
|
+
def set_timestamps_on_save
|
24
|
+
return unless dirty?
|
25
|
+
set_timestamps
|
26
|
+
end
|
27
|
+
|
25
28
|
def set_timestamps
|
26
|
-
return unless dirty? || new_record?
|
27
29
|
TIMESTAMP_PROPERTIES.each do |name,(_type,proc)|
|
28
|
-
if
|
29
|
-
|
30
|
+
if property = properties[name]
|
31
|
+
property.set(self, proc.call(self, property))
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -52,7 +54,10 @@ module DataMapper
|
|
52
54
|
end # module ClassMethods
|
53
55
|
|
54
56
|
class InvalidTimestampName < RuntimeError; end
|
57
|
+
|
58
|
+
Model.append_inclusions self
|
55
59
|
end # module Timestamp
|
60
|
+
|
56
61
|
# include Timestamp or Timestamps, it still works
|
57
|
-
|
62
|
+
Timestamp = Timestamps
|
58
63
|
end # module DataMapper
|
@@ -1,13 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
|
-
|
4
|
-
# run the specs with dm-validations, if available
|
5
|
-
begin
|
6
|
-
gem 'dm-validations', '0.9.11'
|
7
|
-
require 'dm-validations'
|
8
|
-
rescue LoadError
|
9
|
-
# do nothing
|
10
|
-
end
|
1
|
+
require 'spec_helper'
|
11
2
|
|
12
3
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
13
4
|
describe 'DataMapper::Timestamp' do
|
@@ -86,6 +77,34 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
86
77
|
green_smoothie.updated_at.should eql(original_updated_at)
|
87
78
|
green_smoothie.updated_on.should eql(original_updated_on)
|
88
79
|
end
|
80
|
+
|
81
|
+
describe '#touch' do
|
82
|
+
it 'should update the updated_at/on fields' do
|
83
|
+
green_smoothie = GreenSmoothie.create(:name => 'Mango')
|
84
|
+
|
85
|
+
time_tomorrow = DateTime.now + 1
|
86
|
+
date_tomorrow = Date.today + 1
|
87
|
+
DateTime.stub!(:now).and_return { time_tomorrow }
|
88
|
+
Date.stub!(:today).and_return { date_tomorrow }
|
89
|
+
|
90
|
+
green_smoothie.touch
|
91
|
+
|
92
|
+
green_smoothie.updated_at.should eql(time_tomorrow)
|
93
|
+
green_smoothie.updated_on.should eql(date_tomorrow)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should not update the created_at/on fields' do
|
97
|
+
green_smoothie = GreenSmoothie.create(:name => 'Mango')
|
98
|
+
|
99
|
+
original_created_at = green_smoothie.created_at
|
100
|
+
original_created_on = green_smoothie.created_on
|
101
|
+
|
102
|
+
green_smoothie.touch
|
103
|
+
|
104
|
+
green_smoothie.created_at.should equal(original_created_at)
|
105
|
+
green_smoothie.created_on.should equal(original_created_on)
|
106
|
+
end
|
107
|
+
end
|
89
108
|
end
|
90
109
|
|
91
110
|
describe "explicit property declaration" do
|
@@ -96,10 +115,10 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
96
115
|
|
97
116
|
property :id, Serial
|
98
117
|
property :name, String
|
99
|
-
property :created_at, DateTime
|
100
|
-
property :created_on, Date
|
101
|
-
property :updated_at, DateTime
|
102
|
-
property :updated_on, Date
|
118
|
+
property :created_at, DateTime, :nullable => false, :auto_validation => false
|
119
|
+
property :created_on, Date, :nullable => false, :auto_validation => false
|
120
|
+
property :updated_at, DateTime, :nullable => false, :auto_validation => false
|
121
|
+
property :updated_on, Date, :nullable => false, :auto_validation => false
|
103
122
|
|
104
123
|
auto_migrate!
|
105
124
|
end
|
@@ -123,26 +142,26 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
123
142
|
it "should set the *at properties" do
|
124
143
|
@klass.timestamps :at
|
125
144
|
|
126
|
-
@klass.properties.should
|
145
|
+
@klass.properties.should be_named(:created_at)
|
127
146
|
@klass.properties[:created_at].type.should == DateTime
|
128
|
-
@klass.properties.should
|
147
|
+
@klass.properties.should be_named(:updated_at)
|
129
148
|
@klass.properties[:updated_at].type.should == DateTime
|
130
149
|
end
|
131
150
|
|
132
151
|
it "should set the *on properties" do
|
133
152
|
@klass.timestamps :on
|
134
153
|
|
135
|
-
@klass.properties.should
|
154
|
+
@klass.properties.should be_named(:created_on)
|
136
155
|
@klass.properties[:created_on].type.should == Date
|
137
|
-
@klass.properties.should
|
156
|
+
@klass.properties.should be_named(:updated_on)
|
138
157
|
@klass.properties[:updated_on].type.should == Date
|
139
158
|
end
|
140
159
|
|
141
160
|
it "should set multiple properties" do
|
142
161
|
@klass.timestamps :created_at, :updated_on
|
143
162
|
|
144
|
-
@klass.properties.should
|
145
|
-
@klass.properties.should
|
163
|
+
@klass.properties.should be_named(:created_at)
|
164
|
+
@klass.properties.should be_named(:updated_on)
|
146
165
|
end
|
147
166
|
|
148
167
|
it "should fail on unknown property name" do
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
|
-
require 'pathname'
|
2
1
|
require 'rubygems'
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
# Use local dm-core if running from a typical dev checkout.
|
4
|
+
lib = File.join('..', '..', 'dm-core', 'lib')
|
5
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib)
|
6
|
+
require 'dm-core'
|
6
7
|
|
7
|
-
|
8
|
+
# Use local dm-validations if running from a typical dev checkout.
|
9
|
+
lib = File.join('..', 'dm-validations', 'lib')
|
10
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib)
|
11
|
+
require 'dm-validations'
|
12
|
+
|
13
|
+
# Support running specs with 'rake spec' and 'spec'
|
14
|
+
$LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib')
|
15
|
+
|
16
|
+
require 'dm-timestamps'
|
8
17
|
|
9
18
|
def load_driver(name, default_uri)
|
10
19
|
return false if ENV['ADAPTER'] != name.to_s
|
data/tasks/install.rb
CHANGED
@@ -4,7 +4,7 @@ end
|
|
4
4
|
|
5
5
|
desc "Install #{GEM_NAME} #{GEM_VERSION}"
|
6
6
|
task :install => [ :package ] do
|
7
|
-
sudo_gem "install
|
7
|
+
sudo_gem "install pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
|
8
8
|
end
|
9
9
|
|
10
10
|
desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
|
data/tasks/spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
begin
|
2
|
-
gem 'rspec', '~>1.2'
|
3
|
-
require 'spec'
|
4
2
|
require 'spec/rake/spectask'
|
5
3
|
|
6
4
|
task :default => [ :spec ]
|
@@ -8,16 +6,18 @@ begin
|
|
8
6
|
desc 'Run specifications'
|
9
7
|
Spec::Rake::SpecTask.new(:spec) do |t|
|
10
8
|
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
11
|
-
t.
|
9
|
+
t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
|
12
10
|
|
13
11
|
begin
|
14
|
-
|
12
|
+
require 'rcov'
|
15
13
|
t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
|
16
14
|
t.rcov_opts << '--exclude' << 'spec'
|
17
15
|
t.rcov_opts << '--text-summary'
|
18
16
|
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
19
17
|
rescue LoadError
|
20
18
|
# rcov not installed
|
19
|
+
rescue SyntaxError
|
20
|
+
# rcov syntax invalid
|
21
21
|
end
|
22
22
|
end
|
23
23
|
rescue LoadError
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-timestamps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Foy Savas
|
@@ -9,19 +9,10 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: dm-core
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - "="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.11
|
24
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
25
16
|
description: DataMapper plugin for magical timestamps
|
26
17
|
email:
|
27
18
|
- foysavas [a] gmail [d] com
|
@@ -30,15 +21,15 @@ executables: []
|
|
30
21
|
extensions: []
|
31
22
|
|
32
23
|
extra_rdoc_files:
|
33
|
-
- README.
|
24
|
+
- README.rdoc
|
34
25
|
- LICENSE
|
35
26
|
- TODO
|
36
|
-
- History.
|
27
|
+
- History.rdoc
|
37
28
|
files:
|
38
|
-
- History.
|
29
|
+
- History.rdoc
|
39
30
|
- LICENSE
|
40
31
|
- Manifest.txt
|
41
|
-
- README.
|
32
|
+
- README.rdoc
|
42
33
|
- Rakefile
|
43
34
|
- TODO
|
44
35
|
- lib/dm-timestamps.rb
|
@@ -49,11 +40,13 @@ files:
|
|
49
40
|
- tasks/install.rb
|
50
41
|
- tasks/spec.rb
|
51
42
|
has_rdoc: true
|
52
|
-
homepage: http://github.com/
|
43
|
+
homepage: http://github.com/datamapper/dm-more/tree/master/dm-timestamps
|
44
|
+
licenses: []
|
45
|
+
|
53
46
|
post_install_message:
|
54
47
|
rdoc_options:
|
55
48
|
- --main
|
56
|
-
- README.
|
49
|
+
- README.rdoc
|
57
50
|
require_paths:
|
58
51
|
- lib
|
59
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -71,9 +64,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
64
|
requirements: []
|
72
65
|
|
73
66
|
rubyforge_project: datamapper
|
74
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.5
|
75
68
|
signing_key:
|
76
|
-
specification_version:
|
69
|
+
specification_version: 3
|
77
70
|
summary: DataMapper plugin for magical timestamps
|
78
71
|
test_files: []
|
79
72
|
|