allowy 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/allowy.gemspec +1 -1
- data/lib/allowy/access_control.rb +14 -16
- data/lib/allowy/context.rb +14 -16
- data/lib/allowy/matchers.rb +1 -6
- data/lib/allowy/version.rb +1 -1
- data/spec/context_spec.rb +0 -27
- metadata +16 -16
data/allowy.gemspec
CHANGED
@@ -5,25 +5,23 @@ module Allowy
|
|
5
5
|
attr_reader :context
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def can?(action, *args)
|
14
|
-
m = "#{action}?"
|
15
|
-
raise UndefinedAction.new("The #{self.class.name} needs to have #{m} method. Please define it.") unless self.respond_to? m
|
16
|
-
send(m, *args)
|
17
|
-
end
|
8
|
+
def initialize(ctx)
|
9
|
+
@context = ctx
|
10
|
+
end
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
def can?(action, *args)
|
13
|
+
m = "#{action}?"
|
14
|
+
raise UndefinedAction.new("The #{self.class.name} needs to have #{m} method. Please define it.") unless self.respond_to? m
|
15
|
+
send(m, *args)
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
18
|
+
def cannot?(*args)
|
19
|
+
not can?(*args)
|
26
20
|
end
|
27
21
|
|
22
|
+
def authorize!(*args)
|
23
|
+
raise AccessDenied.new("Not authorized", args.first, args[1]) unless can?(*args)
|
24
|
+
end
|
28
25
|
end
|
26
|
+
|
29
27
|
end
|
data/lib/allowy/context.rb
CHANGED
@@ -21,27 +21,25 @@ module Allowy
|
|
21
21
|
module Context
|
22
22
|
extend ActiveSupport::Concern
|
23
23
|
|
24
|
-
module InstanceMethods
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def allowy_context
|
26
|
+
self
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def current_allowy
|
30
|
+
@current_allowy ||= ::Allowy::Registry.new(allowy_context)
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
def can?(action, subject, *args)
|
34
|
+
current_allowy.access_control_for!(subject).can?(action, subject, *args)
|
35
|
+
end
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
def cannot?(*args)
|
38
|
+
current_allowy.access_control_for!(subject).cannot?(action, subject, *args)
|
39
|
+
end
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
41
|
+
def authorize!(action, subject, *args)
|
42
|
+
current_allowy.access_control_for!(subject).authorize!(action, subject, *args)
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
data/lib/allowy/matchers.rb
CHANGED
@@ -7,15 +7,10 @@ module Allowy
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def say msg
|
10
|
-
"#{msg} #{@action} #{@subject.inspect}"
|
11
|
-
' with ' + @context.inspect
|
12
|
-
else
|
13
|
-
''
|
14
|
-
end
|
10
|
+
"#{msg} #{@action} #{@subject.inspect}"
|
15
11
|
end
|
16
12
|
|
17
13
|
def matches?(access_control)
|
18
|
-
@context = access_control.context
|
19
14
|
access_control.can?(@action, @subject)
|
20
15
|
end
|
21
16
|
|
data/lib/allowy/version.rb
CHANGED
data/spec/context_spec.rb
CHANGED
@@ -1,33 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Allowy
|
4
|
-
module Context
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
module InstanceMethods
|
8
|
-
|
9
|
-
def allowy_context
|
10
|
-
self
|
11
|
-
end
|
12
|
-
|
13
|
-
def current_allowy
|
14
|
-
@current_allowy ||= ::Allowy::Registry.new(allowy_context)
|
15
|
-
end
|
16
|
-
|
17
|
-
def can?(action, subject, *args)
|
18
|
-
current_allowy.access_control_for!(subject).can?(action, subject, *args)
|
19
|
-
end
|
20
|
-
|
21
|
-
def cannot?(*args)
|
22
|
-
current_allowy.access_control_for!(subject).cannot?(action, subject, *args)
|
23
|
-
end
|
24
|
-
|
25
|
-
def authorize!(action, subject, *args)
|
26
|
-
current_allowy.access_control_for!(subject).authorize!(action, subject, *args)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
4
|
class SampleContext
|
32
5
|
include Context
|
33
6
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: allowy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
16
|
-
requirement: &
|
16
|
+
requirement: &70283147409820 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70283147409820
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &70283147409320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
|
-
- -
|
30
|
+
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '3.2'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70283147409320
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70283147408900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70283147408900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: pry
|
49
|
-
requirement: &
|
49
|
+
requirement: &70283147408440 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70283147408440
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: guard
|
60
|
-
requirement: &
|
60
|
+
requirement: &70283147408020 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70283147408020
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70283147407600 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70283147407600
|
80
80
|
description: Allowy provides CanCan-like way of checking permission but doesn't enforce
|
81
81
|
a tight DSL giving you more control
|
82
82
|
email:
|