surrounded 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/surrounded/context.rb +28 -7
- data/lib/surrounded/version.rb +1 -1
- data/surrounded.gemspec +0 -1
- data/test/example_proxy_test.rb +2 -2
- data/test/role_context_method_test.rb +4 -5
- data/test/test_helper.rb +13 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36e7bbdfc696cc211fbf80ab3f1c63f60b9d36ee
|
4
|
+
data.tar.gz: a43d73f2915efb6a66dd4cb027a5f9bab34c058f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b5072dac15714ce52bfa92d6bff0ccf3756f80ec9cf3ca9c722e50220f27658f58ede2c89f36f2fa29e2e0c0a0524a13021e301c68064a13b50742590de4b6
|
7
|
+
data.tar.gz: 1e52f4a952f68aa1ca5773647115752237ea362c485859ab80964f1e5ea44f9a0bd4737072203fd346fc22b8607874fbb4852ec25d4619f677ef9b4cbc4dbe18
|
data/lib/surrounded/context.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
require 'set'
|
2
2
|
require 'surrounded/context/role_map'
|
3
|
-
|
3
|
+
|
4
|
+
# Some features are only available in versions of Ruby
|
5
|
+
# where this method is true
|
6
|
+
def module_method_rebinding?
|
7
|
+
return @__module_method_rebinding__ if defined?(@__module_method_rebinding__)
|
8
|
+
sample_method = Enumerable.instance_method(:to_a)
|
9
|
+
@__module_method_rebinding__ = begin
|
10
|
+
!!sample_method.bind(Object.new)
|
11
|
+
rescue TypeError
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
4
15
|
|
5
16
|
module Surrounded
|
6
17
|
module Context
|
@@ -17,9 +28,11 @@ module Surrounded
|
|
17
28
|
@default_role_type = type
|
18
29
|
end
|
19
30
|
|
20
|
-
def new(*)
|
21
|
-
instance =
|
22
|
-
instance.
|
31
|
+
def new(*args, &block)
|
32
|
+
instance = allocate
|
33
|
+
instance.send(:preinitialize)
|
34
|
+
instance.send(:initialize, *args, &block)
|
35
|
+
instance.send(:postinitialize)
|
23
36
|
instance
|
24
37
|
end
|
25
38
|
|
@@ -63,7 +76,7 @@ module Surrounded
|
|
63
76
|
klass.send(:include, Surrounded)
|
64
77
|
end
|
65
78
|
|
66
|
-
if
|
79
|
+
if module_method_rebinding?
|
67
80
|
def interface(name, &block)
|
68
81
|
class_basename = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
69
82
|
interface_name = class_basename + 'Interface'
|
@@ -90,10 +103,10 @@ module Surrounded
|
|
90
103
|
|
91
104
|
class_eval "
|
92
105
|
def initialize(#{setup_args.join(',')})
|
93
|
-
|
106
|
+
preinitialize
|
94
107
|
arguments = method(__method__).parameters.map{|arg| eval(arg[1].to_s) }
|
95
108
|
map_roles(#{setup_args}.zip(arguments))
|
96
|
-
|
109
|
+
postinitialize
|
97
110
|
end
|
98
111
|
"
|
99
112
|
end
|
@@ -146,6 +159,14 @@ module Surrounded
|
|
146
159
|
|
147
160
|
private
|
148
161
|
|
162
|
+
def preinitialize
|
163
|
+
@__apply_role_policy = self.class.send(:__apply_role_policy)
|
164
|
+
end
|
165
|
+
|
166
|
+
def postinitialize
|
167
|
+
apply_roles if __apply_role_policy == :initialize
|
168
|
+
end
|
169
|
+
|
149
170
|
def role_map
|
150
171
|
@role_map ||= RoleMap.new
|
151
172
|
end
|
data/lib/surrounded/version.rb
CHANGED
data/surrounded.gemspec
CHANGED
data/test/example_proxy_test.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
3
|
describe Surrounded::Context, '.role' do
|
5
4
|
class RoleContextTester
|
6
5
|
extend Surrounded::Context
|
@@ -20,7 +19,7 @@ describe Surrounded::Context, '.role' do
|
|
20
19
|
error = assert_raises(NameError){
|
21
20
|
RoleContextTester::Admin
|
22
21
|
}
|
23
|
-
assert_match
|
22
|
+
assert_match(/private constant/, error.message)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -42,10 +41,10 @@ describe Surrounded::Context, '.role' do
|
|
42
41
|
error = assert_raises(NameError){
|
43
42
|
WrapperRoleContext::Admin
|
44
43
|
}
|
45
|
-
assert_match
|
44
|
+
assert_match(/private constant/, error.message)
|
46
45
|
end
|
47
46
|
end
|
48
|
-
if
|
47
|
+
if test_rebinding_methods?
|
49
48
|
class InterfaceContext
|
50
49
|
extend Surrounded::Context
|
51
50
|
|
@@ -80,7 +79,7 @@ describe Surrounded::Context, '.role' do
|
|
80
79
|
error = assert_raises(NameError){
|
81
80
|
InterfaceContext::AdminInterface
|
82
81
|
}
|
83
|
-
assert_match
|
82
|
+
assert_match(/private constant/, error.message)
|
84
83
|
end
|
85
84
|
|
86
85
|
it 'creates a private accessor method' do
|
data/test/test_helper.rb
CHANGED
@@ -25,4 +25,17 @@ class TestContext
|
|
25
25
|
trigger :access_other_object do
|
26
26
|
user.other_user.name
|
27
27
|
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# This is a different implementation of module_method_rebinding?
|
31
|
+
# created in order to check that the behavior of the code is correct.
|
32
|
+
#
|
33
|
+
# This method is used in tests and module_method_rebinding? is used
|
34
|
+
# in the library code.
|
35
|
+
def test_rebinding_methods?
|
36
|
+
unbound = Enumerable.instance_method(:count)
|
37
|
+
unbound.bind(Object.new)
|
38
|
+
true
|
39
|
+
rescue TypeError
|
40
|
+
false
|
28
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surrounded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '''Jim Gay'''
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: triad
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.1.2
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: redcard
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.1.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|