brassbound-dci 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/brassbound/context.rb +13 -3
- data/lib/brassbound/util.rb +1 -0
- data/lib/brassbound/version.rb +1 -1
- metadata +4 -4
data/lib/brassbound/context.rb
CHANGED
@@ -30,12 +30,12 @@ module Brassbound::Context
|
|
30
30
|
|
31
31
|
require 'brassbound/util'
|
32
32
|
|
33
|
+
# The currently executing context. Stored as a thread-local variable, so
|
34
|
+
# each thread can have its own current context.
|
33
35
|
def self.current
|
34
36
|
Thread.current[:brassbound_context]
|
35
37
|
end
|
36
38
|
|
37
|
-
RoleMapping = Struct.new(:role_module, :data_object)
|
38
|
-
|
39
39
|
# A Hash containing all of the declared role mappings for this context.
|
40
40
|
# The keys of the Hash are the declared role names, while the values
|
41
41
|
# are the associated RoleMapping objects.
|
@@ -149,15 +149,25 @@ module Brassbound::Context
|
|
149
149
|
# After the #execute method has returned, it will unapply all role mappings
|
150
150
|
# and set the current context back to its previous value.
|
151
151
|
def call(*args)
|
152
|
+
in_context do
|
153
|
+
self.execute(*args)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def in_context(&block)
|
152
160
|
old_context = ::Brassbound::Context.current
|
153
161
|
Thread.current[:brassbound_context] = self
|
154
162
|
|
155
163
|
roles.each_key(&method(:apply_role))
|
156
164
|
begin
|
157
|
-
|
165
|
+
block.call
|
158
166
|
ensure
|
159
167
|
roles.each_key(&method(:unapply_role))
|
160
168
|
Thread.current[:brassbound_context] = old_context
|
161
169
|
end
|
162
170
|
end
|
171
|
+
|
172
|
+
RoleMapping = Struct.new(:role_module, :data_object)
|
163
173
|
end
|
data/lib/brassbound/util.rb
CHANGED
data/lib/brassbound/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brassbound-dci
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70188456933260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.10.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70188456933260
|
25
25
|
description: Brassbound is a simple but strict implementation of the Data, Context,
|
26
26
|
and Interaction (DCI) paradigm for Ruby.
|
27
27
|
email:
|