surrounded 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/surrounded/access_control.rb +5 -2
- data/lib/surrounded/context/initializing.rb +33 -0
- data/lib/surrounded/context/role_builders.rb +64 -0
- data/lib/surrounded/context.rb +51 -113
- data/lib/surrounded/east_oriented.rb +1 -1
- data/lib/surrounded/version.rb +5 -1
- data/test/example_proxy_test.rb +3 -0
- data/test/example_wrapper_test.rb +1 -1
- data/test/role_context_method_test.rb +1 -0
- data/test/surrounded_context_test.rb +57 -29
- data/test/test_helper.rb +10 -0
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea4a7bea400ebf873e76985cffb1ddff7aa481ff
|
4
|
+
data.tar.gz: 5baeada83ee58583aa93f3e5764565e18983f2a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2d4bc4c9435035b92a93fb78f51942e1b8223c0012c5e48d61cb1b0a11c674144604e32e22c9c7a7e94b00721625e47c38b79e9157fb0e82d6a43ef686f3f3b
|
7
|
+
data.tar.gz: a5273eca6dbfb05540166d248ffb9d4b8434721f7e6241fc4682d051f823356f547f0ef4a25ebfa6f8a35d975e25c09a9d28257639fbcafef81c235b83d3fbed
|
@@ -16,7 +16,7 @@ module Surrounded
|
|
16
16
|
end
|
17
17
|
alias_method :guard, :disallow
|
18
18
|
|
19
|
-
def trigger_return_content(name)
|
19
|
+
def trigger_return_content(name, *args, &block)
|
20
20
|
%{
|
21
21
|
|
22
22
|
method_restrictor = "disallow_#{name}?"
|
@@ -29,7 +29,8 @@ module Surrounded
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def define_access_method(name, &block)
|
32
|
-
|
32
|
+
mod = Module.new
|
33
|
+
mod.class_eval {
|
33
34
|
define_method "disallow_#{name}?" do
|
34
35
|
begin
|
35
36
|
apply_roles if __apply_role_policy == :trigger
|
@@ -39,6 +40,8 @@ module Surrounded
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
}
|
43
|
+
const_set("SurroundedAccess#{name}", mod)
|
44
|
+
include mod
|
42
45
|
end
|
43
46
|
|
44
47
|
module AccessMethods
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Surrounded
|
2
|
+
module Context
|
3
|
+
module Initializing
|
4
|
+
def new(*args, &block)
|
5
|
+
instance = allocate
|
6
|
+
instance.send(:preinitialize)
|
7
|
+
instance.send(:initialize, *args, &block)
|
8
|
+
instance.send(:postinitialize)
|
9
|
+
instance
|
10
|
+
end
|
11
|
+
|
12
|
+
# Shorthand for creating an instance level initialize method which
|
13
|
+
# handles the mapping of the given arguments to their named role.
|
14
|
+
def initialize(*setup_args)
|
15
|
+
private_attr_reader(*setup_args)
|
16
|
+
|
17
|
+
mod = Module.new
|
18
|
+
line = __LINE__
|
19
|
+
mod.class_eval "
|
20
|
+
def initialize(#{setup_args.join(',')})
|
21
|
+
preinitialize
|
22
|
+
arguments = method(__method__).parameters.map{|arg| eval(arg[1].to_s) }
|
23
|
+
@role_map = RoleMap.new
|
24
|
+
map_roles(#{setup_args}.zip(arguments))
|
25
|
+
postinitialize
|
26
|
+
end
|
27
|
+
", __FILE__, line
|
28
|
+
const_set("ContextInitializer", mod)
|
29
|
+
include mod
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Some features are only available in versions of Ruby
|
2
|
+
# where this method is true
|
3
|
+
unless defined?(module_method_rebinding?)
|
4
|
+
def module_method_rebinding?
|
5
|
+
return @__module_method_rebinding__ if defined?(@__module_method_rebinding__)
|
6
|
+
sample_method = Enumerable.instance_method(:to_a)
|
7
|
+
@__module_method_rebinding__ = begin
|
8
|
+
!!sample_method.bind(Object.new)
|
9
|
+
rescue TypeError
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Surrounded
|
16
|
+
module Context
|
17
|
+
module RoleBuilders
|
18
|
+
|
19
|
+
# Define behaviors for your role players
|
20
|
+
def role(name, type=nil, &block)
|
21
|
+
role_type = type || default_role_type
|
22
|
+
if role_type == :module
|
23
|
+
mod_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
24
|
+
mod = Module.new(&block)
|
25
|
+
mod.send(:include, ::Surrounded)
|
26
|
+
private_const_set(mod_name, mod)
|
27
|
+
else
|
28
|
+
meth = method(role_type)
|
29
|
+
meth.call(name, &block)
|
30
|
+
end
|
31
|
+
rescue NameError => e
|
32
|
+
raise e.extend(InvalidRoleType)
|
33
|
+
end
|
34
|
+
alias_method :role_methods, :role
|
35
|
+
|
36
|
+
# Create a named behavior for a role using the standard library SimpleDelegator.
|
37
|
+
def wrap(name, &block)
|
38
|
+
require 'delegate'
|
39
|
+
wrapper_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
40
|
+
klass = private_const_set(wrapper_name, Class.new(SimpleDelegator, &block))
|
41
|
+
klass.send(:include, Surrounded)
|
42
|
+
end
|
43
|
+
alias_method :wrapper, :wrap
|
44
|
+
|
45
|
+
|
46
|
+
if module_method_rebinding?
|
47
|
+
# Create an object which will bind methods to the role player
|
48
|
+
def interface(name, &block)
|
49
|
+
class_basename = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
50
|
+
interface_name = class_basename + 'Interface'
|
51
|
+
|
52
|
+
behavior = private_const_set(interface_name, Module.new(&block))
|
53
|
+
|
54
|
+
require 'surrounded/context/negotiator'
|
55
|
+
undef_method(name)
|
56
|
+
define_method(name) do
|
57
|
+
instance_variable_set("@#{name}", Negotiator.new(role_map.assigned_player(name), behavior))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/lib/surrounded/context.rb
CHANGED
@@ -1,23 +1,11 @@
|
|
1
1
|
require 'set'
|
2
2
|
require 'surrounded/context/role_map'
|
3
|
+
require 'surrounded/context/role_builders'
|
4
|
+
require 'surrounded/context/initializing'
|
3
5
|
require 'surrounded/access_control'
|
4
6
|
require 'surrounded/shortcuts'
|
5
7
|
require 'surrounded/east_oriented'
|
6
8
|
|
7
|
-
# Some features are only available in versions of Ruby
|
8
|
-
# where this method is true
|
9
|
-
unless defined?(module_method_rebinding?)
|
10
|
-
def module_method_rebinding?
|
11
|
-
return @__module_method_rebinding__ if defined?(@__module_method_rebinding__)
|
12
|
-
sample_method = Enumerable.instance_method(:to_a)
|
13
|
-
@__module_method_rebinding__ = begin
|
14
|
-
!!sample_method.bind(Object.new)
|
15
|
-
rescue TypeError
|
16
|
-
false
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
9
|
# Extend your classes with Surrounded::Context to handle their
|
22
10
|
# initialization and application of behaviors to the role players
|
23
11
|
# passed into the constructor.
|
@@ -27,20 +15,13 @@ end
|
|
27
15
|
module Surrounded
|
28
16
|
module Context
|
29
17
|
def self.extended(base)
|
18
|
+
base.extend RoleBuilders, Initializing
|
30
19
|
base.class_eval {
|
31
20
|
@triggers = Set.new
|
32
21
|
include InstanceMethods
|
33
22
|
}
|
34
23
|
end
|
35
24
|
|
36
|
-
def new(*args, &block)
|
37
|
-
instance = allocate
|
38
|
-
instance.send(:preinitialize)
|
39
|
-
instance.send(:initialize, *args, &block)
|
40
|
-
instance.send(:postinitialize)
|
41
|
-
instance
|
42
|
-
end
|
43
|
-
|
44
25
|
# Provides a Set of all available trigger methods where
|
45
26
|
# behaviors will be applied to the roles before execution
|
46
27
|
# and removed afterward.
|
@@ -87,64 +68,6 @@ module Surrounded
|
|
87
68
|
@__apply_role_policy ||= :trigger
|
88
69
|
end
|
89
70
|
|
90
|
-
# Shorthand for creating an instance level initialize method which
|
91
|
-
# handles the mapping of the given arguments to their named role.
|
92
|
-
def initialize(*setup_args)
|
93
|
-
private_attr_reader(*setup_args)
|
94
|
-
|
95
|
-
class_eval "
|
96
|
-
def initialize(#{setup_args.join(',')})
|
97
|
-
preinitialize
|
98
|
-
arguments = method(__method__).parameters.map{|arg| eval(arg[1].to_s) }
|
99
|
-
@role_map = RoleMap.new
|
100
|
-
map_roles(#{setup_args}.zip(arguments))
|
101
|
-
postinitialize
|
102
|
-
end
|
103
|
-
", __FILE__, __LINE__
|
104
|
-
end
|
105
|
-
|
106
|
-
# Create a named behavior for a role using the standard library SimpleDelegator.
|
107
|
-
def wrap(name, &block)
|
108
|
-
require 'delegate'
|
109
|
-
wrapper_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
110
|
-
klass = private_const_set(wrapper_name, Class.new(SimpleDelegator, &block))
|
111
|
-
klass.send(:include, Surrounded)
|
112
|
-
end
|
113
|
-
alias_method :wrapper, :wrap
|
114
|
-
|
115
|
-
if module_method_rebinding?
|
116
|
-
# Create an object which will bind methods to the role player
|
117
|
-
def interface(name, &block)
|
118
|
-
class_basename = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
119
|
-
interface_name = class_basename + 'Interface'
|
120
|
-
|
121
|
-
behavior = private_const_set(interface_name, Module.new(&block))
|
122
|
-
|
123
|
-
require 'surrounded/context/negotiator'
|
124
|
-
undef_method(name)
|
125
|
-
define_method(name) do
|
126
|
-
instance_variable_set("@#{name}", Negotiator.new(role_map.assigned_player(name), behavior))
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# Define behaviors for your role players
|
132
|
-
def role(name, type=nil, &block)
|
133
|
-
role_type = type || default_role_type
|
134
|
-
if role_type == :module
|
135
|
-
mod_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
136
|
-
mod = Module.new(&block)
|
137
|
-
mod.send(:include, ::Surrounded)
|
138
|
-
private_const_set(mod_name, mod)
|
139
|
-
else
|
140
|
-
meth = method(role_type)
|
141
|
-
meth.call(name, &block)
|
142
|
-
end
|
143
|
-
rescue NameError => e
|
144
|
-
raise e.extend(InvalidRoleType)
|
145
|
-
end
|
146
|
-
alias_method :role_methods, :role
|
147
|
-
|
148
71
|
# Creates a context instance method which will apply behaviors to role players
|
149
72
|
# before execution and remove the behaviors after execution.
|
150
73
|
#
|
@@ -188,8 +111,10 @@ module Surrounded
|
|
188
111
|
end
|
189
112
|
|
190
113
|
def define_trigger_wrap_method(name)
|
191
|
-
|
192
|
-
|
114
|
+
mod = Module.new
|
115
|
+
line = __LINE__
|
116
|
+
mod.class_eval %{
|
117
|
+
def #{name}(*args, &block)
|
193
118
|
begin
|
194
119
|
apply_roles if __apply_role_policy == :trigger
|
195
120
|
|
@@ -199,11 +124,13 @@ module Surrounded
|
|
199
124
|
remove_roles if __apply_role_policy == :trigger
|
200
125
|
end
|
201
126
|
end
|
202
|
-
}, __FILE__,
|
127
|
+
}, __FILE__, line
|
128
|
+
const_set("SurroundedTrigger#{name.to_s.upcase.sub(/\?\z/,'Query')}", mod)
|
129
|
+
include mod
|
203
130
|
end
|
204
131
|
|
205
|
-
def trigger_return_content(name)
|
206
|
-
%{self.send("__trigger_#{name}")}
|
132
|
+
def trigger_return_content(name, *args, &block)
|
133
|
+
%{self.send("__trigger_#{name}", *args, &block)}
|
207
134
|
end
|
208
135
|
|
209
136
|
# === Utility shortcuts
|
@@ -225,11 +152,15 @@ module Surrounded
|
|
225
152
|
|
226
153
|
# Conditional const_get for a named role behavior
|
227
154
|
def role_const(name)
|
228
|
-
if
|
155
|
+
if role_const_defined?(name)
|
229
156
|
const_get(name)
|
230
157
|
end
|
231
158
|
end
|
232
159
|
|
160
|
+
def role_const_defined?(name)
|
161
|
+
const_defined?(name, false)
|
162
|
+
end
|
163
|
+
|
233
164
|
module InstanceMethods
|
234
165
|
# Check whether a given name is a role inside the context.
|
235
166
|
# The provided block is used to evaluate whether or not the caller
|
@@ -266,22 +197,28 @@ module Surrounded
|
|
266
197
|
|
267
198
|
def map_roles(role_object_array)
|
268
199
|
role_object_array.each do |role, object|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
200
|
+
if self.respond_to?("map_role_#{role}")
|
201
|
+
self.send("map_role_#{role}", object)
|
202
|
+
else
|
203
|
+
map_role(role, role_behavior_name(role), object)
|
204
|
+
map_role_collection(role, role_behavior_name(role), object)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
273
208
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
209
|
+
def map_role_collection(role, mod_name, collection)
|
210
|
+
singular_role_name = singularize_name(role)
|
211
|
+
singular_behavior_name = singularize_name(role_behavior_name(role))
|
212
|
+
if collection.respond_to?(:each_with_index) && role_const_defined?(singular_behavior_name)
|
213
|
+
collection.each_with_index do |item, index|
|
214
|
+
map_role(:"#{singular_role_name}_#{index + 1}", singular_behavior_name, item)
|
278
215
|
end
|
279
216
|
end
|
280
217
|
end
|
281
218
|
|
282
219
|
def map_role(role, mod_name, object)
|
283
220
|
instance_variable_set("@#{role}", object)
|
284
|
-
role_map.update(role, mod_name, object)
|
221
|
+
role_map.update(role, role_module_basename(mod_name), object)
|
285
222
|
end
|
286
223
|
|
287
224
|
def __apply_role_policy
|
@@ -289,12 +226,13 @@ module Surrounded
|
|
289
226
|
end
|
290
227
|
|
291
228
|
def add_interface(role, behavior, object)
|
292
|
-
|
229
|
+
if behavior && role_const_defined?(behavior)
|
230
|
+
applicator = role_const(behavior).is_a?(Class) ? method(:add_class_interface) : method(:add_module_interface)
|
293
231
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
role_player
|
232
|
+
role_player = applicator.call(object, role_const(behavior))
|
233
|
+
map_role(role, behavior, role_player)
|
234
|
+
end
|
235
|
+
role_player || object
|
298
236
|
end
|
299
237
|
|
300
238
|
def add_module_interface(obj, mod)
|
@@ -308,34 +246,34 @@ module Surrounded
|
|
308
246
|
def add_class_interface(obj, klass)
|
309
247
|
wrapper_name = wrap_methods.find{|meth| klass.respond_to?(meth) }
|
310
248
|
return obj if !wrapper_name
|
311
|
-
|
312
249
|
klass.method(wrapper_name).call(obj)
|
313
250
|
end
|
314
251
|
|
315
252
|
def remove_interface(role, behavior, object)
|
316
|
-
|
317
|
-
|
253
|
+
if behavior && role_const_defined?(behavior)
|
254
|
+
remover_name = (module_removal_methods + unwrap_methods).find{|meth| object.respond_to?(meth) }
|
255
|
+
end
|
318
256
|
|
319
257
|
if remover_name
|
320
258
|
role_player = object.send(remover_name)
|
321
259
|
end
|
322
260
|
|
323
|
-
|
261
|
+
role_player || object
|
324
262
|
end
|
325
263
|
|
326
264
|
def apply_roles
|
327
|
-
|
265
|
+
role_map.each do |role, mod_name, object|
|
266
|
+
player = add_interface(role, mod_name, object)
|
267
|
+
player.send(:store_context, self) do; end
|
268
|
+
end
|
328
269
|
end
|
329
270
|
|
330
271
|
def remove_roles
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
def traverse_map(applicator)
|
335
|
-
role_map.each do |role, mod_name, object|
|
336
|
-
if role_const_defined?(mod_name)
|
337
|
-
applicator.call(role, role_const(mod_name), object)
|
272
|
+
role_map.each do |role, mod_name, player|
|
273
|
+
if player.respond_to?(:remove_context, true)
|
274
|
+
player.send(:remove_context) do; end
|
338
275
|
end
|
276
|
+
remove_interface(role, mod_name, player)
|
339
277
|
end
|
340
278
|
end
|
341
279
|
|
@@ -372,7 +310,7 @@ module Surrounded
|
|
372
310
|
end
|
373
311
|
|
374
312
|
def role_const_defined?(name)
|
375
|
-
self.class.
|
313
|
+
self.class.send(:role_const_defined?, name)
|
376
314
|
end
|
377
315
|
|
378
316
|
def singularize_name(name)
|
data/lib/surrounded/version.rb
CHANGED
data/test/example_proxy_test.rb
CHANGED
@@ -14,6 +14,8 @@ class ProxyContext
|
|
14
14
|
"hello from #{name}, the admin interface!"
|
15
15
|
end
|
16
16
|
end
|
17
|
+
wrap :task do
|
18
|
+
end
|
17
19
|
|
18
20
|
trigger :do_something do
|
19
21
|
admin.some_admin_method
|
@@ -29,6 +31,7 @@ class ProxyContext
|
|
29
31
|
end
|
30
32
|
|
31
33
|
ProxyUser = Struct.new(:name)
|
34
|
+
ProxyUser.send(:include, Surrounded)
|
32
35
|
|
33
36
|
describe ProxyContext do
|
34
37
|
let(:user){
|
@@ -4,7 +4,6 @@ require 'test_helper'
|
|
4
4
|
class WrapperContext
|
5
5
|
extend Surrounded::Context
|
6
6
|
|
7
|
-
apply_roles_on(:trigger)
|
8
7
|
initialize(:admin, :task)
|
9
8
|
|
10
9
|
wrap :admin do
|
@@ -12,6 +11,7 @@ class WrapperContext
|
|
12
11
|
'hello from the admin wrapper!'
|
13
12
|
end
|
14
13
|
end
|
14
|
+
wrap :task do; end
|
15
15
|
|
16
16
|
trigger :do_something do
|
17
17
|
admin.some_admin_method
|
@@ -43,6 +43,20 @@ describe Surrounded::Context, '.trigger' do
|
|
43
43
|
}
|
44
44
|
assert_equal "Guille", context.access_other_object
|
45
45
|
end
|
46
|
+
|
47
|
+
it 'preserves arguments and blocks' do
|
48
|
+
result = context.block_method('argument') do |*args, obj|
|
49
|
+
"Having an #{args.first} with #{obj}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'allows usage of regular methods for triggers' do
|
54
|
+
assert context.regular_method_trigger
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'ignores nil trigger names' do
|
58
|
+
assert context.class.send(:trigger)
|
59
|
+
end
|
46
60
|
end
|
47
61
|
|
48
62
|
describe Surrounded::Context, '#role?' do
|
@@ -110,11 +124,7 @@ class RoleAssignmentContext
|
|
110
124
|
user.respond_to?(:a_method!)
|
111
125
|
end
|
112
126
|
|
113
|
-
|
114
|
-
user.respond_to?(:a_method!)
|
115
|
-
end
|
116
|
-
|
117
|
-
trigger :user_ancestors, :other_user_ancestors, :regular_method_trigger
|
127
|
+
trigger :user_ancestors, :other_user_ancestors
|
118
128
|
|
119
129
|
module User
|
120
130
|
def a_method!; end
|
@@ -124,14 +134,47 @@ class RoleAssignmentContext
|
|
124
134
|
end
|
125
135
|
end
|
126
136
|
|
137
|
+
class Special; end
|
138
|
+
class IgnoreExternalConstantsContext
|
139
|
+
extend Surrounded::Context
|
140
|
+
|
141
|
+
initialize :user, :special, :other
|
142
|
+
|
143
|
+
role :other do
|
144
|
+
def something_or_other; end
|
145
|
+
end
|
146
|
+
|
147
|
+
trigger :check_special do
|
148
|
+
special.class
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
127
152
|
describe Surrounded::Context, '.initialize' do
|
128
153
|
it 'defines an initialize method accepting the same arguments' do
|
129
154
|
assert_equal 2, RoleAssignmentContext.instance_method(:initialize).arity
|
130
155
|
end
|
131
156
|
end
|
132
157
|
|
158
|
+
class ClassRoleAssignmentContext
|
159
|
+
extend Surrounded::Context
|
160
|
+
|
161
|
+
initialize(:thing, :the_test)
|
162
|
+
|
163
|
+
trigger :check_user_response do
|
164
|
+
the_test.assert_respond_to thing, :method_from_class
|
165
|
+
end
|
166
|
+
|
167
|
+
class Thing
|
168
|
+
include Surrounded
|
169
|
+
def initialize(obj); end
|
170
|
+
def method_from_class; end
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
133
175
|
describe Surrounded::Context, 'assigning roles' do
|
134
|
-
include Surrounded
|
176
|
+
include Surrounded # the test must be context-aware
|
177
|
+
|
135
178
|
let(:user){ User.new("Jim") }
|
136
179
|
let(:other_user){ CastingUser.new("Guille") }
|
137
180
|
let(:context){ RoleAssignmentContext.new(user, other_user) }
|
@@ -150,23 +193,6 @@ describe Surrounded::Context, 'assigning roles' do
|
|
150
193
|
end
|
151
194
|
|
152
195
|
it 'will use classes as roles' do
|
153
|
-
ClassRoleAssignmentContext = Class.new do
|
154
|
-
extend Surrounded::Context
|
155
|
-
|
156
|
-
initialize(:thing, :the_test)
|
157
|
-
|
158
|
-
trigger :check_user_response do
|
159
|
-
the_test.assert_respond_to thing, :method_from_class
|
160
|
-
end
|
161
|
-
|
162
|
-
class Thing
|
163
|
-
include Surrounded
|
164
|
-
def initialize(obj); end
|
165
|
-
def method_from_class; end
|
166
|
-
end
|
167
|
-
|
168
|
-
end
|
169
|
-
|
170
196
|
user = User.new('Jim')
|
171
197
|
|
172
198
|
context = ClassRoleAssignmentContext.new(user, self)
|
@@ -174,12 +200,11 @@ describe Surrounded::Context, 'assigning roles' do
|
|
174
200
|
assert context.check_user_response
|
175
201
|
end
|
176
202
|
|
177
|
-
it '
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
assert context.class.send(:trigger)
|
203
|
+
it 'does not use constants defined outside the context class' do
|
204
|
+
special = User.new('Special')
|
205
|
+
other = User.new('Other')
|
206
|
+
context = IgnoreExternalConstantsContext.new(user, special, other)
|
207
|
+
assert_equal User, context.check_special
|
183
208
|
end
|
184
209
|
end
|
185
210
|
|
@@ -208,6 +233,9 @@ class CollectionContext
|
|
208
233
|
end
|
209
234
|
end
|
210
235
|
|
236
|
+
role :others do; end
|
237
|
+
role :other do; end
|
238
|
+
|
211
239
|
end
|
212
240
|
|
213
241
|
describe Surrounded::Context, 'auto-assigning roles for collections' do
|
data/test/test_helper.rb
CHANGED
@@ -25,6 +25,16 @@ class TestContext
|
|
25
25
|
trigger :access_other_object do
|
26
26
|
user.other_user.name
|
27
27
|
end
|
28
|
+
|
29
|
+
def block_method(*args, &block)
|
30
|
+
block.call(*args, self)
|
31
|
+
end
|
32
|
+
trigger :block_method
|
33
|
+
|
34
|
+
def regular_method_trigger
|
35
|
+
true
|
36
|
+
end
|
37
|
+
trigger :regular_method_trigger
|
28
38
|
end
|
29
39
|
|
30
40
|
# This is a different implementation of module_method_rebinding?
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surrounded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- '
|
7
|
+
- "'Jim Gay'"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: triad
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.1.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.1.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Gives an object implicit access to other objects in it's environment.
|
@@ -59,9 +59,9 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .simplecov
|
64
|
-
- .travis.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".simplecov"
|
64
|
+
- ".travis.yml"
|
65
65
|
- Gemfile
|
66
66
|
- LICENSE.txt
|
67
67
|
- README.md
|
@@ -70,7 +70,9 @@ files:
|
|
70
70
|
- lib/surrounded.rb
|
71
71
|
- lib/surrounded/access_control.rb
|
72
72
|
- lib/surrounded/context.rb
|
73
|
+
- lib/surrounded/context/initializing.rb
|
73
74
|
- lib/surrounded/context/negotiator.rb
|
75
|
+
- lib/surrounded/context/role_builders.rb
|
74
76
|
- lib/surrounded/context/role_map.rb
|
75
77
|
- lib/surrounded/context_errors.rb
|
76
78
|
- lib/surrounded/east_oriented.rb
|
@@ -97,17 +99,17 @@ require_paths:
|
|
97
99
|
- lib
|
98
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
99
101
|
requirements:
|
100
|
-
- -
|
102
|
+
- - ">="
|
101
103
|
- !ruby/object:Gem::Version
|
102
104
|
version: '0'
|
103
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
106
|
requirements:
|
105
|
-
- -
|
107
|
+
- - ">="
|
106
108
|
- !ruby/object:Gem::Version
|
107
109
|
version: '0'
|
108
110
|
requirements: []
|
109
111
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.0
|
112
|
+
rubygems_version: 2.2.0
|
111
113
|
signing_key:
|
112
114
|
specification_version: 4
|
113
115
|
summary: Create encapsulated environments for your objects.
|