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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de06a08ec4ff4aef5960901b33c6ce1c5f62cc37
4
- data.tar.gz: 5fc28c5ba7fd611458d8071ea2b7b30a9f80aa61
3
+ metadata.gz: 7e071497b1d19cd9aef5830f86707336a1407ba4
4
+ data.tar.gz: 58b569bbdda9a7d5680acbfa2c97e8a866ac9f43
5
5
  SHA512:
6
- metadata.gz: 1ea77c11bb3d86744de4b05fad7179e1cac58e1f26befbb2d8083bcec67aa73c924270c64a90cc87a7cb07cc45d891e48b0ef58710b0c2676e60b22461036fb8
7
- data.tar.gz: 09f2720549ba5c40e27deaf18e585e7cdfcfa50bebff6930dd87df9b17ed7ca5e6aa411f96490a1e6eb4b050b6bb7bb194af85ec6fc95c6796d17dea8e657590
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 permissions(rules = {all: [:index, :show], customer: [], wiring: []})
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 = rules.inject({}){|h, (k, v)| k.class == Array ? h.merge(Hash[k.map{|kk| [kk, v]}]) : h.merge(k => v) }
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
@@ -1,3 +1,3 @@
1
1
  module Petergate
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
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.3
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-27 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler