surrounded 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c6531f19ef8b5dbc0b493ec8e152e9b437a30cb
4
- data.tar.gz: e697f17d7fd567a6267dacd4920818f7fc38479d
3
+ metadata.gz: 349c77c09cbb18c43dff15df5fcb3ce444f6aee1
4
+ data.tar.gz: 61b1e9fb3ce7e7865a624425fbb4fc746644d674
5
5
  SHA512:
6
- metadata.gz: 45331f12b9e8bede773e36f022f1df5950de459b6687b5dad81b960d2cf4d85fbd694b79d4cc94691871dfdae699a0bbe19a54537f544c98e21afd29f20f2e60
7
- data.tar.gz: 0adab8408e419a3437a75bf08f342a15aaef6b6b9090bd1bb3352a09e44eeeebe4bbf6abe638cd4601dcce85daf10180a088e336e0b94e3f021f7de2090aab9b
6
+ metadata.gz: 166ecba24f2037b1a57c80a163f1a2a75506af524d88552af1caa3d6d72ea79cd0693a97df446acbfd7ac903e57b4d8a8c524b21d5f087dbf21fd0ad00c5c4ab
7
+ data.tar.gz: 04b781c0db8fc068de9af65f4fda3f58b3b8d1e4f859c6dfa67800e89be032cc696a5690b6c7adf7661663dea61dd2eea6dbabb74ad915517e04be0faa9d86a1
@@ -9,7 +9,7 @@ module Surrounded
9
9
 
10
10
  def disallow(*names, &block)
11
11
  names.map do |name|
12
- define_method("disallow_#{name}?", &block)
12
+ define_access_method(name, &block)
13
13
  end
14
14
  end
15
15
 
@@ -33,6 +33,20 @@ module Surrounded
33
33
  }
34
34
  end
35
35
 
36
+ def define_access_method(name, &block)
37
+ class_eval {
38
+ meth = AccessMethods.instance_method(:with_roles)
39
+ define_method "disallow_#{name}?" do
40
+ begin
41
+ apply_roles if __apply_role_policy == :trigger
42
+ instance_exec(&block)
43
+ ensure
44
+ remove_roles if __apply_role_policy == :trigger
45
+ end
46
+ end
47
+ }
48
+ end
49
+
36
50
  module AccessMethods
37
51
  def all_triggers
38
52
  self.class.triggers
@@ -44,6 +58,15 @@ module Surrounded
44
58
  !self.respond_to?(method_restrictor, true) || !self.send(method_restrictor)
45
59
  }.to_set
46
60
  end
61
+
62
+ def with_roles(policy = :trigger)
63
+ begin
64
+ apply_roles if __apply_role_policy == policy
65
+ yield
66
+ ensure
67
+ remove_roles if __apply_role_policy == policy
68
+ end
69
+ end
47
70
  end
48
71
  end
49
72
  end
@@ -1,3 +1,3 @@
1
1
  module Surrounded
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
@@ -14,6 +14,20 @@ class FilteredContext
14
14
  disallow :if_ready do
15
15
  user.name != 'Amy'
16
16
  end
17
+
18
+ trigger :check_disallow_behavior do
19
+ # used for disallow check
20
+ end
21
+
22
+ disallow :check_disallow_behavior do
23
+ user.special
24
+ end
25
+
26
+ role :user do
27
+ def special
28
+ 'special user method'
29
+ end
30
+ end
17
31
  end
18
32
 
19
33
  describe Surrounded::Context, 'access control' do
@@ -37,4 +51,8 @@ describe Surrounded::Context, 'access control' do
37
51
  }
38
52
  assert_match(/access to FilteredContext#if_ready is not allowed/i, error.message)
39
53
  end
54
+
55
+ it 'applies roles in disallow blocks' do
56
+ assert_equal 'special user method', context.disallow_check_disallow_behavior?
57
+ end
40
58
  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.7.1
4
+ version: 0.7.2
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-01-22 00:00:00.000000000 Z
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: triad