petergate 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/petergate.rb +28 -2
- data/lib/petergate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e071497b1d19cd9aef5830f86707336a1407ba4
|
4
|
+
data.tar.gz: 58b569bbdda9a7d5680acbfa2c97e8a866ac9f43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6321dfd8c5c5e647340c1f009b29e435a1a815a27e9cb961840482893c0769f7bcd249f027660760128c7d4065e3806651609de242da69453122854dcdd1a670
|
7
|
+
data.tar.gz: 37845a553961fe7b55c6f203f3e72101bc7e24fa3703a76a18fa050a3de59b6ff89b352318c1184de629b07de0bbc17eb990b585ddfe8ec3b865891de1c6e2e4
|
data/lib/petergate.rb
CHANGED
@@ -10,6 +10,14 @@ module Petergate
|
|
10
10
|
ALLREST
|
11
11
|
end
|
12
12
|
|
13
|
+
def all_actions
|
14
|
+
->{self.action_methods.to_a.map(&:to_sym) - [:check_access, :title]}
|
15
|
+
end
|
16
|
+
|
17
|
+
def except_actions(arr = [])
|
18
|
+
->{all_actions.call - arr}
|
19
|
+
end
|
20
|
+
|
13
21
|
def access(rules = {}, &block)
|
14
22
|
if block
|
15
23
|
b_rules = block.call
|
@@ -57,9 +65,27 @@ module Petergate
|
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
|
-
def
|
68
|
+
def parse_permission_rules(rules)
|
69
|
+
rules = rules.inject({}) do |h, (k, v)|
|
70
|
+
special_values = case v.class.to_s
|
71
|
+
when "Symbol"
|
72
|
+
v == :all ? self.action_methods.to_a.map(&:to_sym) - [:check_access, :title] : raise("No action for: #{v}")
|
73
|
+
when "Hash"
|
74
|
+
v[:except].present? ? (self.action_methods.to_a.map(&:to_sym) - [:check_access, :title]) - v[:except] : raise("Invalid values for except: #{v.values}")
|
75
|
+
when "Array"
|
76
|
+
v
|
77
|
+
else
|
78
|
+
raise("No action for: #{v}")
|
79
|
+
end
|
80
|
+
|
81
|
+
h.merge({k => special_values})
|
82
|
+
end
|
61
83
|
# Allows Array's of keys for he same hash.
|
62
|
-
rules
|
84
|
+
rules.inject({}){|h, (k, v)| k.class == Array ? h.merge(Hash[k.map{|kk| [kk, v]}]) : h.merge(k => v) }
|
85
|
+
end
|
86
|
+
|
87
|
+
def permissions(rules = {all: [:index, :show], customer: [], wiring: []})
|
88
|
+
rules = parse_permission_rules(rules)
|
63
89
|
case params[:action].to_sym
|
64
90
|
when *(rules[:all]) # checks where the action can be seen by :all
|
65
91
|
true
|
data/lib/petergate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: petergate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Sloan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|