barristan 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/barristan/version.rb +2 -1
- data/lib/barristan.rb +9 -11
- metadata +2 -2
data/lib/barristan/version.rb
CHANGED
data/lib/barristan.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Barristan
|
3
|
+
def guard(resource, action, user)
|
4
|
+
yield(guarded = Guarded.new)
|
5
|
+
Can.new(resource, action, user).
|
6
|
+
able? ? guarded.authorized! : guarded.forbidden!
|
7
|
+
end
|
8
|
+
|
3
9
|
class Able
|
4
10
|
def can(klasses, action, &block)
|
5
11
|
Array(klasses).each do |klass|
|
@@ -35,11 +41,11 @@ module Barristan
|
|
35
41
|
end
|
36
42
|
|
37
43
|
def authorized!
|
38
|
-
|
44
|
+
@authorized.call
|
39
45
|
end
|
40
46
|
|
41
47
|
def forbidden!
|
42
|
-
|
48
|
+
@forbidden.call
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
@@ -47,15 +53,7 @@ module Barristan
|
|
47
53
|
class << self
|
48
54
|
def new(&block)
|
49
55
|
yield Able.new
|
50
|
-
|
51
|
-
def guard(resource, action, user)
|
52
|
-
yield(guarded = Guarded.new)
|
53
|
-
catch(:guarded) do
|
54
|
-
Can.new(resource, action, user).
|
55
|
-
able? ? guarded.authorized! : guarded.forbidden!
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
56
|
+
Barristan
|
59
57
|
end
|
60
58
|
end
|
61
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barristan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|