micon 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/micon/metadata.rb +7 -7
- data/lib/micon/micon.rb +3 -3
- data/spec/callbacks_spec.rb +6 -6
- metadata +4 -4
data/Rakefile
CHANGED
data/lib/micon/metadata.rb
CHANGED
@@ -96,22 +96,22 @@ module Micon
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
def call_before_scope key
|
99
|
+
def call_before_scope key, container
|
100
100
|
if callbacks = @before_scope[key]
|
101
|
-
callbacks.each{|c| c.call}
|
101
|
+
callbacks.each{|c| c.call container}
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
def call_after_scope key
|
105
|
+
def call_after_scope key, container
|
106
106
|
if callbacks = @after_scope[key]
|
107
|
-
callbacks.each{|c| c.call}
|
107
|
+
callbacks.each{|c| c.call container}
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
def with_scope_callbacks key, &block
|
112
|
-
call_before_scope key
|
111
|
+
def with_scope_callbacks key, container, &block
|
112
|
+
call_before_scope key, container
|
113
113
|
result = block.call
|
114
|
-
call_after_scope key
|
114
|
+
call_after_scope key, container
|
115
115
|
result
|
116
116
|
end
|
117
117
|
|
data/lib/micon/micon.rb
CHANGED
@@ -30,14 +30,14 @@ module Micon
|
|
30
30
|
begin
|
31
31
|
outer_container_or_nil = Thread.current[scope_with_prefix]
|
32
32
|
Thread.current[scope_with_prefix] = container
|
33
|
-
@metadata.with_scope_callbacks scope, &block
|
33
|
+
@metadata.with_scope_callbacks scope, container, &block
|
34
34
|
ensure
|
35
35
|
Thread.current[scope_with_prefix] = outer_container_or_nil
|
36
36
|
end
|
37
37
|
else
|
38
38
|
# not support nested scopes without block
|
39
39
|
Thread.current[scope_with_prefix] = container
|
40
|
-
@metadata.call_before_scope scope
|
40
|
+
@metadata.call_before_scope scope, container
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -47,7 +47,7 @@ module Micon
|
|
47
47
|
scope_with_prefix = add_prefix(scope)
|
48
48
|
raise_without_self "Scope '#{scope}' not active!" unless container = Thread.current[scope_with_prefix]
|
49
49
|
|
50
|
-
@metadata.call_after_scope scope
|
50
|
+
@metadata.call_after_scope scope, container
|
51
51
|
Thread.current[scope_with_prefix] = nil
|
52
52
|
container
|
53
53
|
end
|
data/spec/callbacks_spec.rb
CHANGED
@@ -40,14 +40,14 @@ describe "Callbacks" do
|
|
40
40
|
describe "custom scope callbacks" do
|
41
41
|
it "scope :before and :after callbacks" do
|
42
42
|
check = mock
|
43
|
-
check.should_receive(:before).ordered
|
43
|
+
check.should_receive(:before).with({}).ordered
|
44
44
|
check.should_receive(:run).ordered
|
45
|
-
check.should_receive(:after).ordered
|
46
|
-
check.should_receive(:after2).ordered
|
45
|
+
check.should_receive(:after).with({}).ordered
|
46
|
+
check.should_receive(:after2).with({}).ordered
|
47
47
|
|
48
|
-
Micon.before_scope(:custom){check.before}
|
49
|
-
Micon.after_scope(:custom){check.after}
|
50
|
-
Micon.after_scope(:custom){check.after2}
|
48
|
+
Micon.before_scope(:custom){|container| check.before container}
|
49
|
+
Micon.after_scope(:custom){|container| check.after container}
|
50
|
+
Micon.after_scope(:custom){|container| check.after2 container}
|
51
51
|
|
52
52
|
Micon.activate(:custom, {}){check.run}
|
53
53
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexey Petrushin
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-22 00:00:00 +04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|