surrounded 0.2.0 → 0.2.1
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 +14 -14
- data/lib/surrounded/version.rb +1 -1
- data/lib/surrounded.rb +1 -1
- data/test/example_wrapper_test.rb +2 -4
- data/test/surrounded_context_test.rb +0 -1
- metadata +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 004d807c4309fea2abc8847f5c23aba8994f6829
|
4
|
+
data.tar.gz: 3a42c0a074f5b1e3f179eb3763ab21a36afbcc19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59292a0a8d86b9703e2364df3416613af3ab18695ee6afa064b4597f57c3c0489e0c551bebe00edc6d19b8d9c618f541d78aec23dbc42cc9d81e9f9b9e448755
|
7
|
+
data.tar.gz: f4eb083c7d739c79967aef23e57436770eaadc16ea6a1b30b19cd5a0e8eb59c1a521c7d3733cec411b77b97363426409990b012a5c8b9afd4abe1c194af8208d
|
data/lib/surrounded/context.rb
CHANGED
@@ -17,6 +17,13 @@ module Surrounded
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
+
def wrap(name, &block)
|
21
|
+
require 'delegate'
|
22
|
+
wrapper_name = name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }
|
23
|
+
klass = const_set(wrapper_name, Class.new(SimpleDelegator, &block))
|
24
|
+
klass.send(:include, Surrounded)
|
25
|
+
end
|
26
|
+
|
20
27
|
def apply_roles_on(which)
|
21
28
|
@policy = which
|
22
29
|
end
|
@@ -24,20 +31,13 @@ module Surrounded
|
|
24
31
|
def initialize(*setup_args)
|
25
32
|
private_attr_reader(*setup_args)
|
26
33
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# >
|
35
|
-
|
36
|
-
define_method(:initialize){ |*args|
|
37
|
-
map_roles(setup_args.zip(args))
|
38
|
-
|
39
|
-
apply_roles if policy == :initialize
|
40
|
-
}
|
34
|
+
class_eval "
|
35
|
+
def initialize(#{setup_args.join(',')})
|
36
|
+
arguments = method(__method__).parameters.map{|arg| eval(arg[1].to_s) }
|
37
|
+
map_roles(#{setup_args}.zip(arguments))
|
38
|
+
apply_roles if policy == :initialize
|
39
|
+
end
|
40
|
+
"
|
41
41
|
end
|
42
42
|
|
43
43
|
def private_attr_reader(*method_names)
|
data/lib/surrounded/version.rb
CHANGED
data/lib/surrounded.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
# If you want to use wrappers, here's how you could
|
4
|
-
require 'delegate'
|
5
4
|
class WrapperContext
|
6
5
|
extend Surrounded::Context
|
7
6
|
|
8
7
|
apply_roles_on(:trigger)
|
9
|
-
|
8
|
+
initialize(:admin, :task)
|
10
9
|
|
11
|
-
|
12
|
-
include Surrounded
|
10
|
+
wrap :admin do
|
13
11
|
def some_admin_method
|
14
12
|
'hello from the admin wrapper!'
|
15
13
|
end
|
@@ -119,7 +119,6 @@ end
|
|
119
119
|
|
120
120
|
describe Surrounded::Context, '.setup' do
|
121
121
|
it 'defines an initialize method accepting the same arguments' do
|
122
|
-
skip "not yet implemented. may not be possible"
|
123
122
|
assert_equal 2, RoleAssignmentContext.instance_method(:initialize).arity
|
124
123
|
end
|
125
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surrounded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '''Jim Gay'''
|
@@ -109,4 +109,3 @@ test_files:
|
|
109
109
|
- test/surrounded_context_test.rb
|
110
110
|
- test/surrounded_test.rb
|
111
111
|
- test/test_helper.rb
|
112
|
-
has_rdoc:
|