access_manager 0.1.1 → 0.1.2

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: ff289656f076f55f1e09706bea32a558a3a0e96e
4
- data.tar.gz: fc7966d7942807c2377af604172ce9fa7cf8be7b
3
+ metadata.gz: 8a4dc4ac9e215934f8a2975dbc10e4830efc586e
4
+ data.tar.gz: 0d7fd03cf0d7f56ad70217bc3b9ab3f8eb151062
5
5
  SHA512:
6
- metadata.gz: acaa35dd7632981054e0f70a6da047837fd65a18c1848ff4ce0b4ea9f96e0a3e44fb7d197555304f93c473ea3707ad4404188f7685dc056ae18a9a0b31fbdb2f
7
- data.tar.gz: 1b38494c63f42a24cfd4fe6dbd103b5f4b8b9591d65ecb26a7b10b40bba0ae7114e35011ee144332993ee6c60bd3bd018a064dd8058f4fb1bad31a80625286d4
6
+ metadata.gz: 64f5eb58d18cf5dfd774a3f659a924893d5a3e5decf4f0eefa8d62a558016b6077e4e7c9fb4d079b0047111c5593072bf74ebe843f701841ce3ae1b871f7847c
7
+ data.tar.gz: 26161875a0d145847e622e4fe7088bcd2d245c59dc8b9b313fb952c23becb929d1a9bbbcc2ae55444c3bfc135a97f40c8519b658737f50d1b074b938ec9a9a8a
data/CHANGELOG.md CHANGED
@@ -29,3 +29,7 @@
29
29
  ## v0.1.1
30
30
 
31
31
  * Bugfixes
32
+
33
+ ## v0.1.2
34
+
35
+ * Set access grants to instance
@@ -1,63 +1,59 @@
1
1
  module AccessManager
2
2
  module Control
3
- def self.included(base)
4
- base.extend(ClassMethods)
5
- end
6
-
7
3
  def can_access?(controller, action)
8
- action_codes.any? { |user_action| self.class.access_granted?(controller, action, user_action) }
4
+ action_codes.any? { |user_action| access_granted?(controller, action, user_action) }
9
5
  end
10
6
 
11
7
  def can?(action)
12
8
  action_codes.map(&:to_s).include?(action.to_s)
13
9
  end
14
10
 
15
- module ClassMethods
16
- attr_accessor :access_tree
17
-
18
- def grant_access_with(user_action, args={})
19
- if @access_tree.nil?
20
- @access_tree = { }
21
- end
11
+ def access_granted?(controller, action, user_action)
12
+ if @access_tree.nil?
13
+ set_grants!
14
+ end
22
15
 
23
- args[:to].each do |controller, actions|
24
- if @access_tree[controller.to_sym].nil?
25
- @access_tree[controller.to_sym] = { }
26
- end
16
+ if @access_tree.nil? || @access_tree.empty?
17
+ return false
18
+ end
27
19
 
28
- if actions == :all
29
- if @access_tree[controller.to_sym]['@all'].nil?
30
- @access_tree[controller.to_sym]['@all'] = []
31
- end
20
+ controller_grants = @access_tree[controller.to_sym]
32
21
 
33
- @access_tree[controller.to_sym]['@all'] << user_action
34
- else
35
- actions.each do |action|
36
- if @access_tree[controller.to_sym][action.to_sym].nil?
37
- @access_tree[controller.to_sym][action.to_sym] = []
38
- end
22
+ if controller_grants.nil?
23
+ false
24
+ elsif controller_grants['@all'] && controller_grants['@all'].include?(user_action.to_sym)
25
+ true
26
+ elsif controller_grants[action.to_sym].nil?
27
+ false
28
+ else
29
+ controller_grants[action.to_sym].include?(user_action.to_sym)
30
+ end
31
+ end
39
32
 
40
- @access_tree[controller.to_sym][action.to_sym] << user_action
41
- end
42
- end
43
- end
33
+ def grant_access_with(user_action, args={})
34
+ if @access_tree.nil?
35
+ @access_tree = { }
44
36
  end
45
37
 
46
- def access_granted?(controller, action, user_action)
47
- if @access_tree.nil?
48
- @access_tree = { }
38
+ args[:to].each do |controller, actions|
39
+ if @access_tree[controller.to_sym].nil?
40
+ @access_tree[controller.to_sym] = { }
49
41
  end
50
42
 
51
- controller_grants = @access_tree[controller.to_sym]
43
+ if actions == :all
44
+ if @access_tree[controller.to_sym]['@all'].nil?
45
+ @access_tree[controller.to_sym]['@all'] = []
46
+ end
52
47
 
53
- if controller_grants.nil?
54
- false
55
- elsif controller_grants['@all'] && controller_grants['@all'].include?(user_action.to_sym)
56
- true
57
- elsif controller_grants[action.to_sym].nil?
58
- false
48
+ @access_tree[controller.to_sym]['@all'] << user_action
59
49
  else
60
- controller_grants[action.to_sym].include?(user_action.to_sym)
50
+ actions.each do |action|
51
+ if @access_tree[controller.to_sym][action.to_sym].nil?
52
+ @access_tree[controller.to_sym][action.to_sym] = []
53
+ end
54
+
55
+ @access_tree[controller.to_sym][action.to_sym] << user_action
56
+ end
61
57
  end
62
58
  end
63
59
  end
@@ -1,3 +1,3 @@
1
1
  module AccessManager
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: access_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Hick