access_policy 0.0.5 → 0.0.6

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: feb81c43a683b9e8237ea9c967e2e23c7ff768a1
4
- data.tar.gz: c8ec25b6998f7cc9c6ec47b5de509b3f3226a522
3
+ metadata.gz: 9d51db3ea65aec0cc8750fb55cc8c89366fab2e8
4
+ data.tar.gz: 074fa237875c2d5604196978c72c4640d6775c44
5
5
  SHA512:
6
- metadata.gz: f2acab607775708c0bf8eb59df2d1282e6afb7718039804fee723b248e72f6e16cd0d6dcce8219f10c77b288ec71fdd3e26941e046cf272857789166f1856926
7
- data.tar.gz: 6b7e3d5c100fd6d1a5090a8eaeda60cf1b8daaebbb632fe713b030db9f73ef68f8dad4dbccbb62bdefc35135d212d1953a0488af7012cb88d077baf141a7f66a
6
+ metadata.gz: bb5da0d85c395208135b3d80d1f9ede490d841f1e05591e1b5353f27ccd48c53774d74806c78e76712d456d1b40a4571a2f3981b05e87988768d39d96a1e5007
7
+ data.tar.gz: 3e30ee36034e37de353476ab318528fcbe26b0f5bebf0526adc5114beb3cf5af5b32de5b52cb16bb1cc36359a843e297319472878ffeed8be650a46ee898817b
data/README.md CHANGED
@@ -76,6 +76,10 @@ Or
76
76
  # do some stuff
77
77
  end
78
78
 
79
+ policy_guarded_method 'publish', 'create?' do
80
+ # do some stuff
81
+ end
82
+
79
83
  end
80
84
 
81
85
  ToGuardPolicy = Struct.new(:current_user_or_role, :object_of_kind_to_guard) do
data/lib/access_policy.rb CHANGED
@@ -43,11 +43,11 @@ module AccessPolicy
43
43
 
44
44
  module ClassMethods
45
45
 
46
- def policy_guarded_method(action_name, &block)
46
+ def policy_guarded_method(action_name, query="#{action_name}?" ,&block)
47
47
  unsafe_action_name = unsafe_action_name(action_name)
48
48
 
49
49
  define_method action_name do |*args|
50
- _authorize "#{action_name}?"
50
+ _authorize query
51
51
  self.send(unsafe_action_name, *args)
52
52
  end
53
53
 
@@ -1,3 +1,3 @@
1
1
  module AccessPolicy
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -5,6 +5,10 @@ module AccessPolicySpec
5
5
  def call?
6
6
  current_user && current_user.allowed?
7
7
  end
8
+
9
+ def query?
10
+ raise StandardError, 'query? called'
11
+ end
8
12
  end
9
13
 
10
14
 
@@ -15,6 +19,10 @@ module AccessPolicySpec
15
19
  :return_value
16
20
  end
17
21
 
22
+ policy_guarded_method 'other_method_name', 'query?' do
23
+ :return_value
24
+ end
25
+
18
26
  end
19
27
  end
20
28
 
@@ -63,6 +71,12 @@ describe AccessPolicy do
63
71
  subject.call_unsafe
64
72
  }.not_to raise_error
65
73
  end
74
+
75
+ it 'uses a different name for query when wanted' do
76
+ expect {
77
+ subject.other_method_name
78
+ }.to raise_error(StandardError, 'query? called')
79
+ end
66
80
  end
67
81
 
68
82
  describe '.with_user_or_role' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: access_policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter Späth