dm-observer 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 +3 -2
- data/{README.txt → README.rdoc} +1 -1
- data/Rakefile +2 -3
- data/lib/dm-observer.rb +1 -91
- data/lib/dm-observer/observer.rb +52 -0
- data/lib/dm-observer/version.rb +1 -1
- data/spec/integration/dm-observer_spec.rb +3 -4
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +7 -6
- data/tasks/install.rb +1 -1
- data/tasks/spec.rb +4 -4
- metadata +15 -21
data/Manifest.txt
CHANGED
data/{README.txt → README.rdoc}
RENAMED
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-observer'
|
|
14
13
|
GEM_VERSION = DataMapper::Observer::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 observing Resource Models'
|
22
21
|
|
23
22
|
[ ROOT, ROOT.parent ].each do |dir|
|
data/lib/dm-observer.rb
CHANGED
@@ -1,91 +1 @@
|
|
1
|
-
|
2
|
-
# Observers allow you to add callback hooks to DataMapper::Resource objects
|
3
|
-
# in a separate class. This is great for separating out logic that is not
|
4
|
-
# really part of the model, but needs to be triggered by a model, or models.
|
5
|
-
module Observer
|
6
|
-
|
7
|
-
def self.included(klass)
|
8
|
-
klass.extend(ClassMethods)
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
|
13
|
-
attr_accessor :observing
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
self.observing = []
|
17
|
-
end
|
18
|
-
|
19
|
-
# Assign an Array of Class names to watch.
|
20
|
-
# observe User, Article, Topic
|
21
|
-
def observe(*args)
|
22
|
-
# puts "#{self.to_s} observing... #{args.collect{|c| Extlib::Inflection.classify(c.to_s)}.join(', ')}"
|
23
|
-
self.observing = args
|
24
|
-
end
|
25
|
-
|
26
|
-
def before(sym, &block)
|
27
|
-
self.observing.each do |klass|
|
28
|
-
klass.before(sym.to_sym, &block)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def after(sym, &block)
|
33
|
-
self.observing.each do |klass|
|
34
|
-
klass.after(sym.to_sym, &block)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def before_class_method(sym, &block)
|
39
|
-
self.observing.each do |klass|
|
40
|
-
klass.before_class_method(sym.to_sym, &block)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def after_class_method(sym, &block)
|
45
|
-
self.observing.each do |klass|
|
46
|
-
klass.after_class_method(sym.to_sym, &block)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
end # ClassMethods
|
51
|
-
|
52
|
-
end # Observer
|
53
|
-
end # DataMapper
|
54
|
-
|
55
|
-
if $0 == __FILE__
|
56
|
-
require 'rubygems'
|
57
|
-
|
58
|
-
gem 'dm-core', '0.9.11'
|
59
|
-
require 'dm-core'
|
60
|
-
|
61
|
-
FileUtils.touch(File.join(Dir.pwd, "migration_test.db"))
|
62
|
-
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/migration_test.db")
|
63
|
-
|
64
|
-
class Foo
|
65
|
-
include DataMapper::Resource
|
66
|
-
|
67
|
-
property :id, Integer, :serial => true
|
68
|
-
property :bar, Text
|
69
|
-
end
|
70
|
-
|
71
|
-
Foo.auto_migrate!
|
72
|
-
|
73
|
-
class FooObserver
|
74
|
-
include DataMapper::Observer
|
75
|
-
|
76
|
-
observe :foo
|
77
|
-
|
78
|
-
before :save do
|
79
|
-
raise "Hell!" if self.bar.nil?
|
80
|
-
puts "hi"
|
81
|
-
end
|
82
|
-
|
83
|
-
after :save do
|
84
|
-
puts "bye"
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
Foo.new(:bar => "hello").save
|
90
|
-
|
91
|
-
end
|
1
|
+
require 'dm-observer/observer'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module DataMapper
|
2
|
+
# Observers allow you to add callback hooks to DataMapper::Resource objects
|
3
|
+
# in a separate class. This is great for separating out logic that is not
|
4
|
+
# really part of the model, but needs to be triggered by a model, or models.
|
5
|
+
module Observer
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
attr_accessor :observing
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
self.observing = []
|
17
|
+
end
|
18
|
+
|
19
|
+
# Assign an Array of Class names to watch.
|
20
|
+
# observe User, Article, Topic
|
21
|
+
def observe(*args)
|
22
|
+
self.observing = args
|
23
|
+
end
|
24
|
+
|
25
|
+
def before(sym, &block)
|
26
|
+
self.observing.each do |klass|
|
27
|
+
klass.before(sym.to_sym, &block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def after(sym, &block)
|
32
|
+
self.observing.each do |klass|
|
33
|
+
klass.after(sym.to_sym, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def before_class_method(sym, &block)
|
38
|
+
self.observing.each do |klass|
|
39
|
+
klass.before_class_method(sym.to_sym, &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def after_class_method(sym, &block)
|
44
|
+
self.observing.each do |klass|
|
45
|
+
klass.after_class_method(sym.to_sym, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/lib/dm-observer/version.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe DataMapper::Observer do
|
5
4
|
before :all do
|
6
5
|
class ::Adam
|
7
6
|
include DataMapper::Resource
|
8
7
|
|
9
|
-
property :id,
|
8
|
+
property :id, Serial
|
10
9
|
property :name, String
|
11
10
|
attr_accessor :done
|
12
11
|
|
@@ -37,7 +36,7 @@ describe DataMapper::Observer do
|
|
37
36
|
class Beer
|
38
37
|
include DataMapper::Resource
|
39
38
|
|
40
|
-
property :id,
|
39
|
+
property :id, Serial
|
41
40
|
property :name, String
|
42
41
|
|
43
42
|
def drink
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
require 'pathname'
|
2
1
|
require 'rubygems'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
gem 'dm-core', '0.9.11'
|
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)
|
8
6
|
require 'dm-core'
|
9
7
|
|
10
|
-
|
8
|
+
# Support running specs with 'rake spec' and 'spec'
|
9
|
+
$LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib')
|
10
|
+
|
11
|
+
require 'dm-observer'
|
11
12
|
|
12
13
|
def load_driver(name, default_uri)
|
13
14
|
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-observer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Bates
|
@@ -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 observing Resource Models
|
26
17
|
email:
|
27
18
|
- mark [a] mackframework [d] com
|
@@ -30,18 +21,19 @@ 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-observer.rb
|
36
|
+
- lib/dm-observer/observer.rb
|
45
37
|
- lib/dm-observer/version.rb
|
46
38
|
- spec/integration/dm-observer_spec.rb
|
47
39
|
- spec/spec.opts
|
@@ -49,11 +41,13 @@ files:
|
|
49
41
|
- tasks/install.rb
|
50
42
|
- tasks/spec.rb
|
51
43
|
has_rdoc: true
|
52
|
-
homepage: http://github.com/
|
44
|
+
homepage: http://github.com/datamapper/dm-more/tree/master/dm-observer
|
45
|
+
licenses: []
|
46
|
+
|
53
47
|
post_install_message:
|
54
48
|
rdoc_options:
|
55
49
|
- --main
|
56
|
-
- README.
|
50
|
+
- README.rdoc
|
57
51
|
require_paths:
|
58
52
|
- lib
|
59
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -71,9 +65,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
65
|
requirements: []
|
72
66
|
|
73
67
|
rubyforge_project: datamapper
|
74
|
-
rubygems_version: 1.3.
|
68
|
+
rubygems_version: 1.3.5
|
75
69
|
signing_key:
|
76
|
-
specification_version:
|
70
|
+
specification_version: 3
|
77
71
|
summary: DataMapper plugin for observing Resource Models
|
78
72
|
test_files: []
|
79
73
|
|