surrounded 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +4 -0
- data/.travis.yml +3 -2
- data/README.md +18 -0
- data/lib/surrounded/access_control.rb +1 -1
- data/lib/surrounded/context/forwarding.rb +2 -2
- data/lib/surrounded/context/initializing.rb +6 -1
- data/lib/surrounded/version.rb +1 -1
- data/test/context_forwarding_test.rb +21 -0
- data/test/example_proxy_test.rb +1 -1
- data/test/surrounded_context_test.rb +17 -13
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63bac757a4c7f7b9cb953a51123e31dc3612fa22
|
4
|
+
data.tar.gz: 1afa12d700b0756ce4e22becf4555169d8e4fa10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d508948a224105b736246b96f0a0a8dec5d9bccd9f2000429071135481fe09a3ecac7963e37e684940411a1d02bf89f5697810593469acbc47b7013e4a95820
|
7
|
+
data.tar.gz: 1f68568474713853a086aef3c3e09ce292fbd66dca77c00c68f32afe11a30af593d159ba76c56f31765dd049063646b214f0bf556a302f9fd07be242274f4db1
|
data/.codeclimate.yml
ADDED
data/.travis.yml
CHANGED
@@ -2,8 +2,8 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
rvm:
|
4
4
|
- 2.0.0
|
5
|
-
- 2.1.
|
6
|
-
- 2.2.
|
5
|
+
- 2.1.5
|
6
|
+
- 2.2.2
|
7
7
|
- ruby-head
|
8
8
|
- jruby-head
|
9
9
|
- rbx
|
@@ -11,6 +11,7 @@ env:
|
|
11
11
|
- COVERALLS=true
|
12
12
|
matrix:
|
13
13
|
allow_failures:
|
14
|
+
- rvm: 2.0.0
|
14
15
|
- rvm: ruby-head
|
15
16
|
- rvm: jruby-head
|
16
17
|
- rvm: rbx
|
data/README.md
CHANGED
@@ -53,6 +53,24 @@ There are 2 things left to do:
|
|
53
53
|
1. define behaviors for each role and
|
54
54
|
2. define how you can trigger their actions
|
55
55
|
|
56
|
+
Currently initializing contexts does not require the use of keyword arguments, _but it will in the future_.
|
57
|
+
|
58
|
+
You should consider using explicit names when initialize now by using `keyword_initialize`:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class Employment
|
62
|
+
extend Surrounded::Context
|
63
|
+
|
64
|
+
keyword_initialize :employee, :boss
|
65
|
+
end
|
66
|
+
|
67
|
+
user1 = User.find(1)
|
68
|
+
user2 = User.find(2)
|
69
|
+
context = Employment.new(employee: user1, boss: user2)
|
70
|
+
```
|
71
|
+
|
72
|
+
This will allow you to prepare your accessing code to use keywords.
|
73
|
+
|
56
74
|
## Defining behaviors for roles
|
57
75
|
|
58
76
|
Behaviors for your roles are easily defined just like you define a method. Provide your role a block and define methods there.
|
@@ -3,8 +3,8 @@ module Surrounded
|
|
3
3
|
module Forwarding
|
4
4
|
def forward_trigger(receiver, message, alternate=message)
|
5
5
|
raise(ArgumentError, %{you may not forward '%{m}`} % {m: message}) if ['__id__','__send__'].include?(message.to_s)
|
6
|
-
trigger alternate do
|
7
|
-
self.send(receiver).public_send(message)
|
6
|
+
trigger alternate do |*args, &block|
|
7
|
+
self.send(receiver).public_send(message,*args, &block)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -3,7 +3,7 @@ module Surrounded
|
|
3
3
|
module Initializing
|
4
4
|
# Shorthand for creating an instance level initialize method which
|
5
5
|
# handles the mapping of the given arguments to their named role.
|
6
|
-
def
|
6
|
+
def initialize_without_keywords(*setup_args)
|
7
7
|
private_attr_reader(*setup_args)
|
8
8
|
|
9
9
|
mod = Module.new
|
@@ -17,6 +17,11 @@ module Surrounded
|
|
17
17
|
const_set("ContextInitializer", mod)
|
18
18
|
include mod
|
19
19
|
end
|
20
|
+
def initialize(*setup_args)
|
21
|
+
warn "Deprecated: The behavior of 'initialize' will require keywords in the future
|
22
|
+
Consider using keyword arguments or switching to 'initialize_without_keywords'\n\n"
|
23
|
+
initialize_without_keywords(*setup_args)
|
24
|
+
end
|
20
25
|
|
21
26
|
def keyword_initialize(*setup_args)
|
22
27
|
private_attr_reader(*setup_args)
|
data/lib/surrounded/version.rb
CHANGED
@@ -7,6 +7,8 @@ class Sending
|
|
7
7
|
|
8
8
|
forwarding [:hello, :goodbye] => :one
|
9
9
|
forward_trigger :two, :ping
|
10
|
+
forward_trigger :two, :argumentative
|
11
|
+
forwards :two, :blockhead
|
10
12
|
|
11
13
|
role :one do
|
12
14
|
def hello
|
@@ -22,6 +24,14 @@ class Sending
|
|
22
24
|
def ping
|
23
25
|
one.hello
|
24
26
|
end
|
27
|
+
|
28
|
+
def argumentative(yes, no)
|
29
|
+
[yes, no].join(' and ')
|
30
|
+
end
|
31
|
+
|
32
|
+
def blockhead
|
33
|
+
yield
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
@@ -56,4 +66,15 @@ describe Surrounded::Context, 'forwarding triggers' do
|
|
56
66
|
}
|
57
67
|
assert_match(/you may not forward '__send__/i, error.message)
|
58
68
|
end
|
69
|
+
|
70
|
+
it 'passes arguments' do
|
71
|
+
assert_equal 'YES and NO', context.argumentative('YES','NO')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'passes blocks' do
|
75
|
+
result = context.blockhead do
|
76
|
+
"Put them in the iron maiden. Excellent!"
|
77
|
+
end
|
78
|
+
assert_equal "Put them in the iron maiden. Excellent!", result
|
79
|
+
end
|
59
80
|
end
|
data/test/example_proxy_test.rb
CHANGED
@@ -65,7 +65,7 @@ describe ProxyContext do
|
|
65
65
|
it 'passes missing methods up the ancestry of the object' do
|
66
66
|
err = ->{ context.admin_missing_method }.must_raise(NoMethodError)
|
67
67
|
|
68
|
-
assert_match
|
68
|
+
assert_match(/ProxyUser.*name="Jim"/, err.message)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'allows access to other objects in the context' do
|
@@ -259,21 +259,25 @@ describe Surrounded::Context, 'auto-assigning roles for collections' do
|
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
keyword_initialize :this, :that
|
266
|
-
end
|
262
|
+
begin
|
263
|
+
class Keyworder
|
264
|
+
extend Surrounded::Context
|
267
265
|
|
268
|
-
|
269
|
-
it 'works with keyword arguments' do
|
270
|
-
assert context = Keyworder.new(this: User.new('Jim'), that: User.new('Guille'))
|
266
|
+
keyword_initialize :this, :that
|
271
267
|
end
|
272
268
|
|
273
|
-
|
274
|
-
|
275
|
-
Keyworder.new(this: User.new('
|
276
|
-
|
277
|
-
|
269
|
+
describe Surrounded::Context, 'keyword initializers' do
|
270
|
+
it 'works with keyword arguments' do
|
271
|
+
assert Keyworder.new(this: User.new('Jim'), that: User.new('Guille'))
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'raises errors with missing keywords' do
|
275
|
+
err = assert_raises(ArgumentError){
|
276
|
+
Keyworder.new(this: User.new('Amy'))
|
277
|
+
}
|
278
|
+
assert_match(/missing keyword: that/, err.message)
|
279
|
+
end
|
278
280
|
end
|
281
|
+
rescue SyntaxError
|
282
|
+
STDOUT.puts "No support for keywords"
|
279
283
|
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.9.
|
4
|
+
version: 0.9.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: 2015-05-
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: triad
|
@@ -59,6 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".codeclimate.yml"
|
62
63
|
- ".gitignore"
|
63
64
|
- ".simplecov"
|
64
65
|
- ".travis.yml"
|