dm-timestamps 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +65 -0
- data/TODO +8 -0
- data/lib/dm-timestamps.rb +29 -0
- data/spec/integration/timestamps_spec.rb +71 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +28 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Foy Savas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'spec/rake/spectask'
|
6
|
+
require 'pathname'
|
7
|
+
|
8
|
+
CLEAN.include '{log,pkg}/'
|
9
|
+
|
10
|
+
spec = Gem::Specification.new do |s|
|
11
|
+
s.name = 'dm-timestamps'
|
12
|
+
s.version = '0.9.2'
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.extra_rdoc_files = %w[ README LICENSE TODO ]
|
16
|
+
s.summary = 'DataMapper plugin for magical timestamps'
|
17
|
+
s.description = s.summary
|
18
|
+
s.author = 'Foy Savas'
|
19
|
+
s.email = 'foysavas@gmail.com'
|
20
|
+
s.homepage = 'http://github.com/sam/dm-more/tree/master/dm-timestamps'
|
21
|
+
s.require_path = 'lib'
|
22
|
+
s.files = FileList[ '{lib,spec}/**/*.rb', 'spec/spec.opts', 'Rakefile', *s.extra_rdoc_files ]
|
23
|
+
s.add_dependency('dm-core', "=#{s.version}")
|
24
|
+
end
|
25
|
+
|
26
|
+
task :default => [ :spec ]
|
27
|
+
|
28
|
+
WIN32 = (RUBY_PLATFORM =~ /win32|mingw|cygwin/) rescue nil
|
29
|
+
SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
|
30
|
+
|
31
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
32
|
+
pkg.gem_spec = spec
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "Install #{spec.name} #{spec.version} (default ruby)"
|
36
|
+
task :install => [ :package ] do
|
37
|
+
sh "#{SUDO} gem install --local pkg/#{spec.name}-#{spec.version} --no-update-sources", :verbose => false
|
38
|
+
end
|
39
|
+
|
40
|
+
desc "Uninstall #{spec.name} #{spec.version} (default ruby)"
|
41
|
+
task :uninstall => [ :clobber ] do
|
42
|
+
sh "#{SUDO} gem uninstall #{spec.name} -v#{spec.version} -I -x", :verbose => false
|
43
|
+
end
|
44
|
+
|
45
|
+
namespace :jruby do
|
46
|
+
desc "Install #{spec.name} #{spec.version} with JRuby"
|
47
|
+
task :install => [ :package ] do
|
48
|
+
sh %{#{SUDO} jruby -S gem install --local pkg/#{spec.name}-#{spec.version} --no-update-sources}, :verbose => false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Run specifications'
|
53
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
54
|
+
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
|
55
|
+
t.spec_files = Pathname.glob(Pathname.new(__FILE__).dirname + 'spec/**/*_spec.rb')
|
56
|
+
|
57
|
+
begin
|
58
|
+
t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
|
59
|
+
t.rcov_opts << '--exclude' << 'spec'
|
60
|
+
t.rcov_opts << '--text-summary'
|
61
|
+
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
|
62
|
+
rescue Exception
|
63
|
+
# rcov not installed
|
64
|
+
end
|
65
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'dm-core', '=0.9.2'
|
4
|
+
require 'dm-core'
|
5
|
+
|
6
|
+
module DataMapper
|
7
|
+
module Timestamp
|
8
|
+
TIMESTAMP_PROPERTIES = {
|
9
|
+
:updated_at => lambda { |r| r.updated_at = DateTime.now },
|
10
|
+
:updated_on => lambda { |r| r.updated_on = Date.today },
|
11
|
+
:created_at => lambda { |r| r.created_at ||= DateTime.now },
|
12
|
+
:created_on => lambda { |r| r.created_on ||= Date.today },
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.included(model)
|
16
|
+
model.before :save, :set_timestamp_properties
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def set_timestamp_properties
|
22
|
+
self.class.properties.slice(*TIMESTAMP_PROPERTIES.keys).compact.each do |property|
|
23
|
+
TIMESTAMP_PROPERTIES[property.name][self]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end # module Timestamp
|
27
|
+
|
28
|
+
Resource::append_inclusions Timestamp
|
29
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
|
+
|
4
|
+
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
5
|
+
describe 'DataMapper::Timestamp' do
|
6
|
+
before :all do
|
7
|
+
class GreenSmoothie
|
8
|
+
include DataMapper::Resource
|
9
|
+
|
10
|
+
property :id, Integer, :serial => true
|
11
|
+
property :name, String
|
12
|
+
property :created_at, DateTime
|
13
|
+
property :created_on, Date
|
14
|
+
property :updated_at, DateTime
|
15
|
+
property :updated_on, Date
|
16
|
+
|
17
|
+
auto_migrate!(:default)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
repository(:default).adapter.execute('DELETE from green_smoothies');
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set the created_at/on fields on creation" do
|
26
|
+
repository(:default) do
|
27
|
+
green_smoothie = GreenSmoothie.new(:name => 'Banana')
|
28
|
+
green_smoothie.created_at.should be_nil
|
29
|
+
green_smoothie.created_on.should be_nil
|
30
|
+
green_smoothie.save
|
31
|
+
green_smoothie.created_at.should be_a_kind_of(DateTime)
|
32
|
+
green_smoothie.created_on.should be_a_kind_of(Date)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not alter the create_at/on fields on model updates" do
|
37
|
+
repository(:default) do
|
38
|
+
green_smoothie = GreenSmoothie.new(:id => 2, :name => 'Berry')
|
39
|
+
green_smoothie.created_at.should be_nil
|
40
|
+
green_smoothie.created_on.should be_nil
|
41
|
+
green_smoothie.save
|
42
|
+
original_created_at = green_smoothie.created_at
|
43
|
+
original_created_on = green_smoothie.created_on
|
44
|
+
green_smoothie.name = 'Strawberry'
|
45
|
+
green_smoothie.save
|
46
|
+
green_smoothie.created_at.should eql(original_created_at)
|
47
|
+
green_smoothie.created_on.should eql(original_created_on)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set the updated_at/on fields on creation and on update" do
|
52
|
+
repository(:default) do
|
53
|
+
green_smoothie = GreenSmoothie.new(:name => 'Mango')
|
54
|
+
green_smoothie.updated_at.should be_nil
|
55
|
+
green_smoothie.updated_on.should be_nil
|
56
|
+
green_smoothie.save
|
57
|
+
green_smoothie.updated_at.should be_a_kind_of(DateTime)
|
58
|
+
green_smoothie.updated_on.should be_a_kind_of(Date)
|
59
|
+
original_updated_at = green_smoothie.updated_at
|
60
|
+
original_updated_on = green_smoothie.updated_on
|
61
|
+
sleep 1
|
62
|
+
tomorrow = Date.today + 1
|
63
|
+
Date.should_receive(:today).and_return(tomorrow)
|
64
|
+
green_smoothie.name = 'Cranberry Mango'
|
65
|
+
green_smoothie.save
|
66
|
+
green_smoothie.updated_at.should_not eql(original_updated_at)
|
67
|
+
green_smoothie.updated_on.should_not eql(original_updated_on)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec', '>=1.1.3'
|
3
|
+
require 'spec'
|
4
|
+
require 'pathname'
|
5
|
+
require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-timestamps'
|
6
|
+
|
7
|
+
def load_driver(name, default_uri)
|
8
|
+
return false if ENV['ADAPTER'] != name.to_s
|
9
|
+
|
10
|
+
lib = "do_#{name}"
|
11
|
+
|
12
|
+
begin
|
13
|
+
gem lib, '=0.9.2'
|
14
|
+
require lib
|
15
|
+
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
16
|
+
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
17
|
+
true
|
18
|
+
rescue Gem::LoadError => e
|
19
|
+
warn "Could not load #{lib}: #{e}"
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
ENV['ADAPTER'] ||= 'sqlite3'
|
25
|
+
|
26
|
+
HAS_SQLITE3 = load_driver(:sqlite3, 'sqlite3::memory:')
|
27
|
+
HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test')
|
28
|
+
HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test')
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-timestamps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Foy Savas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-25 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dm-core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - "="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.2
|
23
|
+
version:
|
24
|
+
description: DataMapper plugin for magical timestamps
|
25
|
+
email: foysavas@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README
|
32
|
+
- LICENSE
|
33
|
+
- TODO
|
34
|
+
files:
|
35
|
+
- lib/dm-timestamps.rb
|
36
|
+
- spec/integration/timestamps_spec.rb
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
- spec/spec.opts
|
39
|
+
- Rakefile
|
40
|
+
- README
|
41
|
+
- LICENSE
|
42
|
+
- TODO
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/sam/dm-more/tree/master/dm-timestamps
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.0.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: DataMapper plugin for magical timestamps
|
69
|
+
test_files: []
|
70
|
+
|