dm-userstamp 0.0.3 → 0.0.4
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/.gitignore +5 -0
- data/Rakefile +45 -15
- data/VERSION +1 -0
- data/dm-userstamp.gemspec +50 -0
- data/lib/dm-userstamp.rb +15 -13
- data/spec/integration/userstamp_spec.rb +8 -8
- data/spec/spec_helper.rb +1 -1
- metadata +20 -25
- data/Manifest.txt +0 -11
data/Rakefile
CHANGED
@@ -1,18 +1,48 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "dm-userstamp"
|
8
|
+
gem.summary = %Q{DataMapper plugin to add automatic updating of created_by_id and updated_by_id attributes}
|
9
|
+
gem.email = "richard@livsey.org"
|
10
|
+
gem.homepage = "http://github.com/rlivsey/dm-userstamp"
|
11
|
+
gem.authors = ["Richard Livsey"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
if File.exist?('VERSION.yml')
|
37
|
+
config = YAML.load(File.read('VERSION.yml'))
|
38
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
+
else
|
40
|
+
version = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "dm-userstamp #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
47
|
end
|
17
48
|
|
18
|
-
# vim: syntax=Ruby
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.4
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{dm-userstamp}
|
5
|
+
s.version = "0.0.4"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Richard Livsey"]
|
9
|
+
s.date = %q{2009-10-29}
|
10
|
+
s.email = %q{richard@livsey.org}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.txt"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".gitignore",
|
17
|
+
"History.txt",
|
18
|
+
"LICENSE",
|
19
|
+
"README.txt",
|
20
|
+
"Rakefile",
|
21
|
+
"TODO",
|
22
|
+
"VERSION",
|
23
|
+
"dm-userstamp.gemspec",
|
24
|
+
"lib/.DS_Store",
|
25
|
+
"lib/dm-userstamp.rb",
|
26
|
+
"lib/dm-userstamp/version.rb",
|
27
|
+
"spec/integration/userstamp_spec.rb",
|
28
|
+
"spec/spec.opts",
|
29
|
+
"spec/spec_helper.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/rlivsey/dm-userstamp}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{DataMapper plugin to add automatic updating of created_by_id and updated_by_id attributes}
|
36
|
+
s.test_files = [
|
37
|
+
"spec/integration/userstamp_spec.rb",
|
38
|
+
"spec/spec_helper.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
data/lib/dm-userstamp.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
gem 'dm-core', '>=0.9.
|
3
|
+
gem 'dm-core', '>=0.9.10'
|
4
4
|
require 'dm-core'
|
5
5
|
|
6
6
|
module DataMapper
|
7
|
-
|
8
7
|
module Userstamp
|
9
|
-
|
10
8
|
module Stamper
|
11
9
|
def self.included(base)
|
12
10
|
base.extend(ClassMethods)
|
13
11
|
end
|
14
|
-
|
12
|
+
|
15
13
|
module ClassMethods
|
16
|
-
|
14
|
+
def userstamp_class
|
15
|
+
User
|
16
|
+
end
|
17
|
+
|
17
18
|
def current_user=(user)
|
18
19
|
Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"] = user
|
19
20
|
end
|
@@ -21,15 +22,16 @@ module DataMapper
|
|
21
22
|
def current_user
|
22
23
|
Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"]
|
23
24
|
end
|
24
|
-
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
28
|
-
|
29
|
-
|
27
|
+
|
28
|
+
def self.userstamp_class
|
29
|
+
User
|
30
|
+
end
|
31
|
+
|
30
32
|
USERSTAMP_PROPERTIES = {
|
31
|
-
:created_by_id => lambda { |r| r.created_by_id =
|
32
|
-
:updated_by_id => lambda { |r| r.updated_by_id =
|
33
|
+
:created_by_id => lambda { |r| r.created_by_id = userstamp_class.current_user.id if userstamp_class.current_user && r.new_record? && r.created_by_id.nil? },
|
34
|
+
:updated_by_id => lambda { |r| r.updated_by_id = userstamp_class.current_user.id if userstamp_class.current_user}
|
33
35
|
}
|
34
36
|
|
35
37
|
def self.included(model)
|
@@ -39,11 +41,11 @@ module DataMapper
|
|
39
41
|
private
|
40
42
|
|
41
43
|
def set_userstamp_properties
|
42
|
-
self.class.properties.
|
44
|
+
self.class.properties.values_at(*USERSTAMP_PROPERTIES.keys).compact.each do |property|
|
43
45
|
USERSTAMP_PROPERTIES[property.name][self]
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
47
|
-
|
49
|
+
|
48
50
|
Resource::append_inclusions Userstamp
|
49
51
|
end
|
@@ -35,12 +35,12 @@ describe 'DataMapper::Userstamp' do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
after do
|
38
|
-
repository(:default).adapter.execute('DELETE from users');
|
39
|
-
repository(:default).adapter.execute('DELETE from monkeys');
|
38
|
+
DataMapper.repository(:default).adapter.execute('DELETE from users');
|
39
|
+
DataMapper.repository(:default).adapter.execute('DELETE from monkeys');
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should not set created_by_id if there is no current user" do
|
43
|
-
repository(:default) do
|
43
|
+
DataMapper.repository(:default) do
|
44
44
|
User.current_user = nil
|
45
45
|
monkey = Monkey.new(:name => 'Eric')
|
46
46
|
monkey.save
|
@@ -49,7 +49,7 @@ describe 'DataMapper::Userstamp' do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should not set updated_by_id if there is no current user" do
|
52
|
-
repository(:default) do
|
52
|
+
DataMapper.repository(:default) do
|
53
53
|
User.current_user = nil
|
54
54
|
monkey = Monkey.new(:name => 'Eric')
|
55
55
|
monkey.save
|
@@ -58,7 +58,7 @@ describe 'DataMapper::Userstamp' do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should not set created_by_id if already set" do
|
61
|
-
repository(:default) do
|
61
|
+
DataMapper.repository(:default) do
|
62
62
|
monkey = Monkey.new(:name => 'Eric')
|
63
63
|
monkey.created_by_id = 5
|
64
64
|
monkey.save
|
@@ -68,7 +68,7 @@ describe 'DataMapper::Userstamp' do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should set created_by_id on creation" do
|
71
|
-
repository(:default) do
|
71
|
+
DataMapper.repository(:default) do
|
72
72
|
monkey = Monkey.new(:name => 'Clyde')
|
73
73
|
monkey.created_by_id.should be_nil
|
74
74
|
monkey.save
|
@@ -78,7 +78,7 @@ describe 'DataMapper::Userstamp' do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should not alter created_by_id on model updates" do
|
81
|
-
repository(:default) do
|
81
|
+
DataMapper.repository(:default) do
|
82
82
|
monkey = Monkey.new(:name => 'Chump')
|
83
83
|
monkey.created_by_id.should be_nil
|
84
84
|
monkey.save
|
@@ -90,7 +90,7 @@ describe 'DataMapper::Userstamp' do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should set updated_by_id on creation and on update" do
|
93
|
-
repository(:default) do
|
93
|
+
DataMapper.repository(:default) do
|
94
94
|
monkey = Monkey.new(:name => 'Johnny')
|
95
95
|
monkey.updated_by_id.should be_nil
|
96
96
|
monkey.save
|
data/spec/spec_helper.rb
CHANGED
@@ -11,7 +11,7 @@ def load_driver(name, default_uri)
|
|
11
11
|
lib = "do_#{name}"
|
12
12
|
|
13
13
|
begin
|
14
|
-
gem lib, '
|
14
|
+
gem lib, '>=0.9.10'
|
15
15
|
require lib
|
16
16
|
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
17
17
|
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-userstamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Livsey
|
@@ -9,47 +9,41 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-10-29 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
type: :development
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 1.7.0
|
24
|
-
version:
|
25
|
-
description: DataMapper plugin to add automatic updating of created_by_id and updated_by_id attributes
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
26
17
|
email: richard@livsey.org
|
27
18
|
executables: []
|
28
19
|
|
29
20
|
extensions: []
|
30
21
|
|
31
22
|
extra_rdoc_files:
|
32
|
-
-
|
33
|
-
- Manifest.txt
|
23
|
+
- LICENSE
|
34
24
|
- README.txt
|
35
25
|
files:
|
26
|
+
- .gitignore
|
36
27
|
- History.txt
|
37
28
|
- LICENSE
|
38
|
-
- Manifest.txt
|
39
29
|
- README.txt
|
40
30
|
- Rakefile
|
41
31
|
- TODO
|
32
|
+
- VERSION
|
33
|
+
- dm-userstamp.gemspec
|
34
|
+
- lib/.DS_Store
|
42
35
|
- lib/dm-userstamp.rb
|
43
36
|
- lib/dm-userstamp/version.rb
|
44
37
|
- spec/integration/userstamp_spec.rb
|
45
38
|
- spec/spec.opts
|
46
39
|
- spec/spec_helper.rb
|
47
40
|
has_rdoc: true
|
48
|
-
homepage:
|
41
|
+
homepage: http://github.com/rlivsey/dm-userstamp
|
42
|
+
licenses: []
|
43
|
+
|
49
44
|
post_install_message:
|
50
45
|
rdoc_options:
|
51
|
-
- --
|
52
|
-
- README.txt
|
46
|
+
- --charset=UTF-8
|
53
47
|
require_paths:
|
54
48
|
- lib
|
55
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -66,10 +60,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
60
|
version:
|
67
61
|
requirements: []
|
68
62
|
|
69
|
-
rubyforge_project:
|
70
|
-
rubygems_version: 1.
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
71
65
|
signing_key:
|
72
|
-
specification_version:
|
66
|
+
specification_version: 3
|
73
67
|
summary: DataMapper plugin to add automatic updating of created_by_id and updated_by_id attributes
|
74
|
-
test_files:
|
75
|
-
|
68
|
+
test_files:
|
69
|
+
- spec/integration/userstamp_spec.rb
|
70
|
+
- spec/spec_helper.rb
|