dm-timestamps 0.9.11 → 0.10.0

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.
@@ -1,3 +1,7 @@
1
+ === 0.10.0 / 2009-10-15
2
+
3
+ * Updated to work with dm-core 0.10.0
4
+
1
5
  === 0.9.11 / 2009-03-29
2
6
 
3
7
  * No changes this version
@@ -1,7 +1,7 @@
1
- History.txt
1
+ History.rdoc
2
2
  LICENSE
3
3
  Manifest.txt
4
- README.txt
4
+ README.rdoc
5
5
  Rakefile
6
6
  TODO
7
7
  lib/dm-timestamps.rb
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.txt LICENSE TODO History.txt ] }
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/sam/dm-more/tree/master/#{GEM_NAME}"
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|
@@ -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 Timestamp
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.new_record?) } ],
14
- :created_on => [ Date, lambda { |r, p| r.created_on || (Date.today if r.new_record?) } ],
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 :create, :set_timestamps
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 model.properties.has_property?(name)
29
- model.properties[name].set(self, proc.call(self, model.properties[name])) unless attribute_dirty?(name)
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
- Timestamps = Timestamp
62
+ Timestamp = Timestamps
58
63
  end # module DataMapper
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Timestamps
3
- VERSION = '0.9.11'
3
+ VERSION = '0.10.0'.freeze
4
4
  end
5
5
  end
@@ -1,13 +1,4 @@
1
- require 'pathname'
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 have_property(:created_at)
145
+ @klass.properties.should be_named(:created_at)
127
146
  @klass.properties[:created_at].type.should == DateTime
128
- @klass.properties.should have_property(:updated_at)
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 have_property(:created_on)
154
+ @klass.properties.should be_named(:created_on)
136
155
  @klass.properties[:created_on].type.should == Date
137
- @klass.properties.should have_property(:updated_on)
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 have_property(:created_at)
145
- @klass.properties.should have_property(:updated_on)
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
@@ -1 +1,2 @@
1
1
  --colour
2
+ --loadby random
@@ -1,10 +1,19 @@
1
- require 'pathname'
2
1
  require 'rubygems'
3
2
 
4
- gem 'rspec', '~>1.2'
5
- require 'spec'
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
- require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-timestamps'
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
@@ -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 --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
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}"
@@ -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.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
9
+ t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
12
10
 
13
11
  begin
14
- gem 'rcov', '~>0.8'
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.9.11
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-03-29 00:00:00 -07:00
12
+ date: 2009-09-16 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
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.txt
24
+ - README.rdoc
34
25
  - LICENSE
35
26
  - TODO
36
- - History.txt
27
+ - History.rdoc
37
28
  files:
38
- - History.txt
29
+ - History.rdoc
39
30
  - LICENSE
40
31
  - Manifest.txt
41
- - README.txt
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/sam/dm-more/tree/master/dm-timestamps
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.txt
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.1
67
+ rubygems_version: 1.3.5
75
68
  signing_key:
76
- specification_version: 2
69
+ specification_version: 3
77
70
  summary: DataMapper plugin for magical timestamps
78
71
  test_files: []
79
72