callmeback 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +23 -0
- data/README.rdoc +21 -4
- data/VERSION +1 -1
- data/callmeback.gemspec +15 -2
- data/lib/callmeback.rb +4 -21
- data/spec/app/db/schema.rb +6 -0
- data/spec/app/models/example.rb +5 -122
- data/spec/app/models/example_active_record.rb +11 -0
- data/spec/app/models/example_mongoid.rb +12 -0
- data/spec/app/support/example_definition.rb +126 -0
- data/spec/callmeback_spec.rb +105 -101
- data/spec/spec_helper.rb +3 -0
- metadata +55 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activemodel (3.2.3)
|
5
|
+
activesupport (= 3.2.3)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activerecord (3.2.3)
|
8
|
+
activemodel (= 3.2.3)
|
9
|
+
activesupport (= 3.2.3)
|
10
|
+
arel (~> 3.0.2)
|
11
|
+
tzinfo (~> 0.3.29)
|
12
|
+
activerecord-nulldb-adapter (0.2.3)
|
13
|
+
activerecord (>= 2.0.0)
|
4
14
|
activesupport (3.2.3)
|
5
15
|
i18n (~> 0.6)
|
6
16
|
multi_json (~> 1.0)
|
17
|
+
arel (3.0.2)
|
18
|
+
builder (3.0.4)
|
7
19
|
coderay (1.0.6)
|
8
20
|
diff-lcs (1.1.3)
|
9
21
|
ffi (1.0.11)
|
@@ -21,7 +33,14 @@ GEM
|
|
21
33
|
rdoc
|
22
34
|
json (1.7.1)
|
23
35
|
method_source (0.7.1)
|
36
|
+
mongoid (3.1.3)
|
37
|
+
activemodel (~> 3.2)
|
38
|
+
moped (~> 1.4.2)
|
39
|
+
origin (~> 1.0)
|
40
|
+
tzinfo (~> 0.3.22)
|
41
|
+
moped (1.4.5)
|
24
42
|
multi_json (1.3.4)
|
43
|
+
origin (1.1.0)
|
25
44
|
pry (0.9.9.4)
|
26
45
|
coderay (~> 1.0.5)
|
27
46
|
method_source (~> 0.7.1)
|
@@ -43,16 +62,20 @@ GEM
|
|
43
62
|
simplecov-html (0.5.3)
|
44
63
|
slop (2.4.4)
|
45
64
|
thor (0.14.6)
|
65
|
+
tzinfo (0.3.37)
|
46
66
|
|
47
67
|
PLATFORMS
|
48
68
|
ruby
|
49
69
|
|
50
70
|
DEPENDENCIES
|
71
|
+
activerecord
|
72
|
+
activerecord-nulldb-adapter
|
51
73
|
activesupport (>= 3.2.3)
|
52
74
|
bundler
|
53
75
|
guard
|
54
76
|
guard-rspec
|
55
77
|
jeweler (~> 1.8.3)
|
78
|
+
mongoid
|
56
79
|
pry
|
57
80
|
rdoc (~> 3.12)
|
58
81
|
rspec (~> 2.8.0)
|
data/README.rdoc
CHANGED
@@ -19,25 +19,30 @@ Or add it to your gem file:
|
|
19
19
|
== Usage
|
20
20
|
|
21
21
|
=== Basic
|
22
|
-
Add +include Callmeback+
|
22
|
+
Add +include Callmeback+ to your class:
|
23
23
|
class Example
|
24
24
|
include Callmeback
|
25
25
|
|
26
26
|
before :foo => :bar
|
27
27
|
|
28
|
+
def initialize
|
29
|
+
callmeback!
|
30
|
+
@result = []
|
31
|
+
end
|
32
|
+
|
28
33
|
def foo
|
29
|
-
|
34
|
+
@result << 'foo'
|
30
35
|
end
|
31
36
|
|
32
37
|
def bar
|
33
|
-
|
38
|
+
@result << 'bar'
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
42
|
example = Example.new
|
38
43
|
example.foo #=> ['bar','foo']
|
39
44
|
|
40
|
-
Because
|
45
|
+
Because your methods must be redefined to perform custom callbacks, you need to call +#callmeback!+ on initialization.
|
41
46
|
|
42
47
|
You can use +before+, +after+ and +around+, as if you use the suggested method in the +ActiveSupport::Callbacks+ documentation.
|
43
48
|
To perform the +around+ callbacks, define them like:
|
@@ -49,6 +54,18 @@ To perform the +around+ callbacks, define them like:
|
|
49
54
|
bar
|
50
55
|
end
|
51
56
|
|
57
|
+
=== ActiveRecord and Mongoid
|
58
|
+
|
59
|
+
You may want to use Callmeback on your ActiveRecord or Mongoid models. I recommend you not to redefine the +initialize+ method. Instead please use the +after_initialize+ callback. Here is an example using Mongoid:
|
60
|
+
class Example
|
61
|
+
include Mongoid::Document
|
62
|
+
include Callmeback
|
63
|
+
|
64
|
+
after_initialize do
|
65
|
+
callmeback!
|
66
|
+
end
|
67
|
+
...
|
68
|
+
|
52
69
|
=== Array of callbacks
|
53
70
|
You can pass an array of callback method symbol:
|
54
71
|
before :foo => [:bar, :bar]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
data/callmeback.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "callmeback"
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sebastien Azimi"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-04-26"
|
13
13
|
s.description = ""
|
14
14
|
s.email = "sebstp@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,7 +28,11 @@ Gem::Specification.new do |s|
|
|
28
28
|
"VERSION",
|
29
29
|
"callmeback.gemspec",
|
30
30
|
"lib/callmeback.rb",
|
31
|
+
"spec/app/db/schema.rb",
|
31
32
|
"spec/app/models/example.rb",
|
33
|
+
"spec/app/models/example_active_record.rb",
|
34
|
+
"spec/app/models/example_mongoid.rb",
|
35
|
+
"spec/app/support/example_definition.rb",
|
32
36
|
"spec/callmeback_spec.rb",
|
33
37
|
"spec/spec_helper.rb"
|
34
38
|
]
|
@@ -51,6 +55,9 @@ Gem::Specification.new do |s|
|
|
51
55
|
s.add_development_dependency(%q<guard>, [">= 0"])
|
52
56
|
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
53
57
|
s.add_development_dependency(%q<pry>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<activerecord>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<mongoid>, [">= 0"])
|
54
61
|
else
|
55
62
|
s.add_dependency(%q<activesupport>, [">= 3.2.3"])
|
56
63
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
@@ -61,6 +68,9 @@ Gem::Specification.new do |s|
|
|
61
68
|
s.add_dependency(%q<guard>, [">= 0"])
|
62
69
|
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
63
70
|
s.add_dependency(%q<pry>, [">= 0"])
|
71
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
72
|
+
s.add_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
|
73
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
64
74
|
end
|
65
75
|
else
|
66
76
|
s.add_dependency(%q<activesupport>, [">= 3.2.3"])
|
@@ -72,6 +82,9 @@ Gem::Specification.new do |s|
|
|
72
82
|
s.add_dependency(%q<guard>, [">= 0"])
|
73
83
|
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
74
84
|
s.add_dependency(%q<pry>, [">= 0"])
|
85
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
86
|
+
s.add_dependency(%q<activerecord-nulldb-adapter>, [">= 0"])
|
87
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
75
88
|
end
|
76
89
|
end
|
77
90
|
|
data/lib/callmeback.rb
CHANGED
@@ -5,24 +5,7 @@ module Callmeback
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
include ActiveSupport::Callbacks
|
7
7
|
|
8
|
-
|
9
|
-
if defined?(Mongoid::Document)
|
10
|
-
after_initialize do
|
11
|
-
callback_binding
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def initialize(*args, &block)
|
17
|
-
super(*args, &block)
|
18
|
-
|
19
|
-
unless defined?(Mongoid::Document)
|
20
|
-
# Overwrite the initialize method to perform the defined callbacks binding
|
21
|
-
callback_binding
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def callback_binding
|
8
|
+
def callmeback!
|
26
9
|
self.class.callmeback_methods.each do |callback_prefix, callback_array|
|
27
10
|
callback_array.each do |callback_hash|
|
28
11
|
callback_hash.each do |callback_key, callbacks|
|
@@ -38,11 +21,11 @@ module Callmeback
|
|
38
21
|
binded_methods.each do |binded|
|
39
22
|
callbacks.each do |callback|
|
40
23
|
|
41
|
-
binded_suffix = "method_#{self.class.callmeback_method_index}"
|
24
|
+
binded_suffix = :"method_#{self.class.callmeback_method_index}"
|
42
25
|
self.class.callmeback_method_index += 1
|
43
26
|
|
44
|
-
prefixed_wrapped_binded = "callmeback_wrapped_#{binded_suffix}"
|
45
|
-
prefixed_unwrapped_binded = "callmeback_unwrapped_#{binded_suffix}"
|
27
|
+
prefixed_wrapped_binded = :"callmeback_wrapped_#{binded_suffix}"
|
28
|
+
prefixed_unwrapped_binded = :"callmeback_unwrapped_#{binded_suffix}"
|
46
29
|
|
47
30
|
class_eval do
|
48
31
|
define_method prefixed_wrapped_binded do
|
data/spec/app/models/example.rb
CHANGED
@@ -1,127 +1,10 @@
|
|
1
|
-
|
2
|
-
include Callmeback
|
3
|
-
|
4
|
-
attr_accessor :result
|
5
|
-
|
6
|
-
before :before_foo => :bar
|
7
|
-
after :after_foo => :bar
|
8
|
-
around :around_foo => :around_bar
|
9
|
-
|
10
|
-
before :multiple_before_foo => [:bar, :bar]
|
11
|
-
after :multiple_after_foo => [:bar, :bar]
|
12
|
-
around :multiple_around_foo => [:around_bar, :around_bar]
|
13
|
-
|
14
|
-
before :complex_foo => :bar
|
15
|
-
around :complex_foo => [:around_bar, :around_bar]
|
16
|
-
after :complex_foo => [:bar, :bar]
|
17
|
-
|
18
|
-
before( /^regex_before_.+$/ => :bar )
|
19
|
-
|
20
|
-
before :block_before_foo do
|
21
|
-
bar
|
22
|
-
end
|
23
|
-
|
24
|
-
after :block_after_foo do
|
25
|
-
bar
|
26
|
-
end
|
27
|
-
|
28
|
-
around :block_around_foo do |&block|
|
29
|
-
bar
|
30
|
-
block.call
|
31
|
-
bar
|
32
|
-
end
|
33
|
-
|
34
|
-
before :complex_with_blocks_foo do
|
35
|
-
bar
|
36
|
-
bar
|
37
|
-
end
|
38
|
-
after :complex_with_blocks_foo do
|
39
|
-
bar
|
40
|
-
end
|
41
|
-
around :complex_with_blocks_foo do |&block|
|
42
|
-
bar
|
43
|
-
block.call
|
44
|
-
bar
|
45
|
-
end
|
46
|
-
|
47
|
-
before :complex_with_methods_and_blocks_foo => [:bar, :bar]
|
48
|
-
after :complex_with_methods_and_blocks_foo do
|
49
|
-
bar
|
50
|
-
end
|
51
|
-
around :complex_with_methods_and_blocks_foo do |&block|
|
52
|
-
bar
|
53
|
-
block.call
|
54
|
-
bar
|
55
|
-
end
|
56
|
-
|
57
|
-
before(/^regex_block_before.+$/) do
|
58
|
-
bar
|
59
|
-
end
|
60
|
-
|
61
|
-
before(/^regex_block_method_before.+$/) do
|
62
|
-
bar
|
63
|
-
end
|
64
|
-
after(/^regex_block_method_before.+$/ => :bar)
|
65
|
-
|
66
|
-
around [:array_around_method1_foo, :array_around_method2_foo] => :around_bar
|
67
|
-
|
68
|
-
before %w{array_block_before_method1_foo array_block_before_method2_foo} do
|
69
|
-
bar
|
70
|
-
end
|
71
|
-
|
72
|
-
before %w{array_block_method_before_method1_foo array_block_method_before_method2_foo} do
|
73
|
-
bar
|
74
|
-
end
|
75
|
-
after %w{array_block_method_before_method1_foo array_block_method_before_method2_foo} => :bar
|
1
|
+
require "#{File.dirname(__FILE__)}/../support/example_definition.rb"
|
76
2
|
|
3
|
+
class Example
|
4
|
+
include ExampleDefinition
|
77
5
|
|
78
6
|
def initialize
|
79
|
-
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
%w{
|
84
|
-
before after
|
85
|
-
around
|
86
|
-
multiple_before
|
87
|
-
multiple_after
|
88
|
-
multiple_around
|
89
|
-
complex
|
90
|
-
block_before
|
91
|
-
block_after
|
92
|
-
block_around
|
93
|
-
complex_with_blocks
|
94
|
-
complex_with_methods_and_blocks
|
95
|
-
regex_before_method1
|
96
|
-
regex_before_method2
|
97
|
-
regex_block_before_method1
|
98
|
-
regex_block_before_method2
|
99
|
-
regex_block_method_before_method1
|
100
|
-
regex_block_method_before_method2
|
101
|
-
array_around_method1
|
102
|
-
array_around_method2
|
103
|
-
array_block_before_method1
|
104
|
-
array_block_before_method2
|
105
|
-
array_block_method_before_method1
|
106
|
-
array_block_method_before_method2
|
107
|
-
}.each do |prefix|
|
108
|
-
define_method "#{prefix}_foo" do
|
109
|
-
foo
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
private
|
114
|
-
def foo
|
115
|
-
@result << 'foo'
|
116
|
-
end
|
117
|
-
|
118
|
-
def bar
|
119
|
-
@result << 'bar'
|
120
|
-
end
|
121
|
-
|
122
|
-
def around_bar
|
123
|
-
bar
|
124
|
-
yield
|
125
|
-
bar
|
7
|
+
callmeback!
|
8
|
+
self.result = []
|
126
9
|
end
|
127
10
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module ExampleDefinition
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Callmeback
|
6
|
+
|
7
|
+
included do
|
8
|
+
attr_accessor :result
|
9
|
+
|
10
|
+
before :before_foo => :bar
|
11
|
+
after :after_foo => :bar
|
12
|
+
around :around_foo => :around_bar
|
13
|
+
|
14
|
+
before :multiple_before_foo => [:bar, :bar]
|
15
|
+
after :multiple_after_foo => [:bar, :bar]
|
16
|
+
around :multiple_around_foo => [:around_bar, :around_bar]
|
17
|
+
|
18
|
+
before :complex_foo => :bar
|
19
|
+
around :complex_foo => [:around_bar, :around_bar]
|
20
|
+
after :complex_foo => [:bar, :bar]
|
21
|
+
|
22
|
+
before( /^regex_before_.+$/ => :bar )
|
23
|
+
|
24
|
+
before :block_before_foo do
|
25
|
+
bar
|
26
|
+
end
|
27
|
+
|
28
|
+
after :block_after_foo do
|
29
|
+
bar
|
30
|
+
end
|
31
|
+
|
32
|
+
around :block_around_foo do |&block|
|
33
|
+
bar
|
34
|
+
block.call
|
35
|
+
bar
|
36
|
+
end
|
37
|
+
|
38
|
+
before :complex_with_blocks_foo do
|
39
|
+
bar
|
40
|
+
bar
|
41
|
+
end
|
42
|
+
after :complex_with_blocks_foo do
|
43
|
+
bar
|
44
|
+
end
|
45
|
+
around :complex_with_blocks_foo do |&block|
|
46
|
+
bar
|
47
|
+
block.call
|
48
|
+
bar
|
49
|
+
end
|
50
|
+
|
51
|
+
before :complex_with_methods_and_blocks_foo => [:bar, :bar]
|
52
|
+
after :complex_with_methods_and_blocks_foo do
|
53
|
+
bar
|
54
|
+
end
|
55
|
+
around :complex_with_methods_and_blocks_foo do |&block|
|
56
|
+
bar
|
57
|
+
block.call
|
58
|
+
bar
|
59
|
+
end
|
60
|
+
|
61
|
+
before(/^regex_block_before.+$/) do
|
62
|
+
bar
|
63
|
+
end
|
64
|
+
|
65
|
+
before(/^regex_block_method_before.+$/) do
|
66
|
+
bar
|
67
|
+
end
|
68
|
+
after(/^regex_block_method_before.+$/ => :bar)
|
69
|
+
|
70
|
+
around [:array_around_method1_foo, :array_around_method2_foo] => :around_bar
|
71
|
+
|
72
|
+
before %w{array_block_before_method1_foo array_block_before_method2_foo} do
|
73
|
+
bar
|
74
|
+
end
|
75
|
+
|
76
|
+
before %w{array_block_method_before_method1_foo array_block_method_before_method2_foo} do
|
77
|
+
bar
|
78
|
+
end
|
79
|
+
after %w{array_block_method_before_method1_foo array_block_method_before_method2_foo} => :bar
|
80
|
+
|
81
|
+
|
82
|
+
%w{
|
83
|
+
before after
|
84
|
+
around
|
85
|
+
multiple_before
|
86
|
+
multiple_after
|
87
|
+
multiple_around
|
88
|
+
complex
|
89
|
+
block_before
|
90
|
+
block_after
|
91
|
+
block_around
|
92
|
+
complex_with_blocks
|
93
|
+
complex_with_methods_and_blocks
|
94
|
+
regex_before_method1
|
95
|
+
regex_before_method2
|
96
|
+
regex_block_before_method1
|
97
|
+
regex_block_before_method2
|
98
|
+
regex_block_method_before_method1
|
99
|
+
regex_block_method_before_method2
|
100
|
+
array_around_method1
|
101
|
+
array_around_method2
|
102
|
+
array_block_before_method1
|
103
|
+
array_block_before_method2
|
104
|
+
array_block_method_before_method1
|
105
|
+
array_block_method_before_method2
|
106
|
+
}.each do |prefix|
|
107
|
+
define_method "#{prefix}_foo" do
|
108
|
+
foo
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def foo
|
114
|
+
@result << 'foo'
|
115
|
+
end
|
116
|
+
|
117
|
+
def bar
|
118
|
+
@result << 'bar'
|
119
|
+
end
|
120
|
+
|
121
|
+
def around_bar
|
122
|
+
bar
|
123
|
+
yield
|
124
|
+
bar
|
125
|
+
end
|
126
|
+
end
|
data/spec/callmeback_spec.rb
CHANGED
@@ -2,123 +2,127 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe Callmeback do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
it "should have created 3 methods: before, after, around" do
|
10
|
-
[:before, :after, :around].each do |method_name|
|
11
|
-
expect{ Example.method method_name }.to_not raise_error(NameError)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe ".before" do
|
16
|
-
it "should fire a callback before the original method is executed" do
|
17
|
-
example.before_foo.should == %w{bar foo}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe ".after" do
|
22
|
-
it "should fire a callback after the original method is executed" do
|
23
|
-
example.after_foo.should == %w{foo bar}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe ".around" do
|
28
|
-
it "should fire a callback around the original method is executed" do
|
29
|
-
example.around_foo.should == %w{bar foo bar}
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "the callback value is an array of methods" do
|
34
|
-
describe ".before" do
|
35
|
-
it "should fire array-length callbacks before the original method is executed" do
|
36
|
-
example.multiple_before_foo.should == %w{bar bar foo}
|
5
|
+
%w{Example ExampleActiveRecord ExampleMongoid}.each do |klass|
|
6
|
+
context "using #{klass}" do
|
7
|
+
let(:example) do
|
8
|
+
klass.constantize.new
|
37
9
|
end
|
38
|
-
end
|
39
10
|
|
40
|
-
|
41
|
-
|
42
|
-
|
11
|
+
it "should have created 3 methods: before, after, around" do
|
12
|
+
[:before, :after, :around].each do |method_name|
|
13
|
+
expect{ klass.constantize.method method_name }.to_not raise_error(NameError)
|
14
|
+
end
|
43
15
|
end
|
44
|
-
end
|
45
16
|
|
46
|
-
|
47
|
-
|
48
|
-
|
17
|
+
describe ".before" do
|
18
|
+
it "should fire a callback before the original method is executed" do
|
19
|
+
example.before_foo.should == %w{bar foo}
|
20
|
+
end
|
49
21
|
end
|
50
|
-
end
|
51
|
-
end
|
52
22
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
context "the gem should handle blocks as callbacks" do
|
60
|
-
it "should fire a callback block before the original method is executed" do
|
61
|
-
example.block_before_foo.should == %w{bar foo}
|
62
|
-
end
|
23
|
+
describe ".after" do
|
24
|
+
it "should fire a callback after the original method is executed" do
|
25
|
+
example.after_foo.should == %w{foo bar}
|
26
|
+
end
|
27
|
+
end
|
63
28
|
|
64
|
-
|
65
|
-
|
66
|
-
|
29
|
+
describe ".around" do
|
30
|
+
it "should fire a callback around the original method is executed" do
|
31
|
+
example.around_foo.should == %w{bar foo bar}
|
32
|
+
end
|
33
|
+
end
|
67
34
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
35
|
+
context "the callback value is an array of methods" do
|
36
|
+
describe ".before" do
|
37
|
+
it "should fire array-length callbacks before the original method is executed" do
|
38
|
+
example.multiple_before_foo.should == %w{bar bar foo}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe ".after" do
|
43
|
+
it "should fire array-length callbacks after the original method is executed" do
|
44
|
+
example.multiple_after_foo.should == %w{foo bar bar}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".around" do
|
49
|
+
it "should fire array-length callbacks around the original method is executed" do
|
50
|
+
example.multiple_around_foo.should == %w{bar bar foo bar bar}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
72
54
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
55
|
+
context "the gem should handle complex callback structures" do
|
56
|
+
it "should fire the callbacks in the order of their call" do
|
57
|
+
example.complex_foo.should == %w{bar bar bar foo bar bar bar bar}
|
58
|
+
end
|
59
|
+
end
|
78
60
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
61
|
+
context "the gem should handle blocks as callbacks" do
|
62
|
+
it "should fire a callback block before the original method is executed" do
|
63
|
+
example.block_before_foo.should == %w{bar foo}
|
64
|
+
end
|
84
65
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
example.result.clear
|
89
|
-
example.regex_before_method2_foo.should == %w{bar foo}
|
90
|
-
end
|
66
|
+
it "should fire a callback block after the original method is executed" do
|
67
|
+
example.block_after_foo.should == %w{foo bar}
|
68
|
+
end
|
91
69
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
70
|
+
it "should fire a callback block around the original method is executed" do
|
71
|
+
example.block_around_foo.should == %w{bar foo bar}
|
72
|
+
end
|
73
|
+
end
|
97
74
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
75
|
+
context "the gem should handle blocks as callbacks" do
|
76
|
+
it "should fire the callbacks in the order of their call" do
|
77
|
+
example.complex_with_blocks_foo.should == %w{bar bar bar foo bar bar}
|
78
|
+
end
|
79
|
+
end
|
104
80
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
81
|
+
context "the gem should handle blocks as callbacks and methods" do
|
82
|
+
it "should fire the callbacks in the order of their call" do
|
83
|
+
example.complex_with_methods_and_blocks_foo.should == %w{bar bar bar foo bar bar}
|
84
|
+
end
|
85
|
+
end
|
111
86
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
87
|
+
context "the gem should handle regex as callback argument" do
|
88
|
+
it "should fire the callback for all the given methods that match the given regex" do
|
89
|
+
example.regex_before_method1_foo.should == %w{bar foo}
|
90
|
+
example.result.clear
|
91
|
+
example.regex_before_method2_foo.should == %w{bar foo}
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should fire the callback for all the given blocks that match the given regex" do
|
95
|
+
example.regex_block_before_method1_foo.should == %w{bar foo}
|
96
|
+
example.result.clear
|
97
|
+
example.regex_block_before_method2_foo.should == %w{bar foo}
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should fire the callback for all the given methods and blocks that match the given regex" do
|
101
|
+
example.regex_block_method_before_method1_foo.should == %w{bar foo bar}
|
102
|
+
example.result.clear
|
103
|
+
example.regex_block_method_before_method2_foo.should == %w{bar foo bar}
|
104
|
+
end
|
105
|
+
end
|
117
106
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
107
|
+
context "the gem should handle array as callback argument" do
|
108
|
+
it "should fire the callback for all the given methods that are included in the given array" do
|
109
|
+
example.array_around_method1_foo.should == %w{bar foo bar}
|
110
|
+
example.result.clear
|
111
|
+
example.array_around_method2_foo.should == %w{bar foo bar}
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should fire the callback for all the given blocks that are included in the given array" do
|
115
|
+
example.array_block_before_method1_foo.should == %w{bar foo}
|
116
|
+
example.result.clear
|
117
|
+
example.array_block_before_method2_foo.should == %w{bar foo}
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should fire the callback for all the given methods and blocks that are included in the given array" do
|
121
|
+
example.array_block_method_before_method1_foo.should == %w{bar foo bar}
|
122
|
+
example.result.clear
|
123
|
+
example.array_block_method_before_method2_foo.should == %w{bar foo bar}
|
124
|
+
end
|
125
|
+
end
|
122
126
|
end
|
123
127
|
end
|
124
128
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
|
4
|
+
require "active_record"
|
5
|
+
ActiveRecord::Base.establish_connection :adapter => :nulldb, :schema => File.join(File.dirname(__FILE__), "app", "db", "schema.rb")
|
6
|
+
|
4
7
|
MODELS = File.join(File.dirname(__FILE__), "app/models")
|
5
8
|
|
6
9
|
require 'rspec'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: callmeback
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -155,6 +155,54 @@ dependencies:
|
|
155
155
|
- - ! '>='
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: activerecord
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: activerecord-nulldb-adapter
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ! '>='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: mongoid
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
type: :development
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ! '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
158
206
|
description: ''
|
159
207
|
email: sebstp@gmail.com
|
160
208
|
executables: []
|
@@ -174,7 +222,11 @@ files:
|
|
174
222
|
- VERSION
|
175
223
|
- callmeback.gemspec
|
176
224
|
- lib/callmeback.rb
|
225
|
+
- spec/app/db/schema.rb
|
177
226
|
- spec/app/models/example.rb
|
227
|
+
- spec/app/models/example_active_record.rb
|
228
|
+
- spec/app/models/example_mongoid.rb
|
229
|
+
- spec/app/support/example_definition.rb
|
178
230
|
- spec/callmeback_spec.rb
|
179
231
|
- spec/spec_helper.rb
|
180
232
|
homepage: http://github.com/suruja/callmeback
|
@@ -192,7 +244,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
192
244
|
version: '0'
|
193
245
|
segments:
|
194
246
|
- 0
|
195
|
-
hash: -
|
247
|
+
hash: -2380151203651981277
|
196
248
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
249
|
none: false
|
198
250
|
requirements:
|