arturo 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
@@ -1,19 +1,24 @@
1
1
  module Arturo
2
2
 
3
- # Adds whitelist and blacklist support to individual features by name.
4
- # Blacklists override whitelists. (In the world of Apache, Features
5
- # are "(deny,allow)".)
3
+ # Adds whitelist and blacklist support to individual features by name
4
+ # or for all features. Blacklists override whitelists. (In the world of
5
+ # Apache, Features are "(deny,allow)".)
6
6
  # @example
7
- # # allow admins:
7
+ # # allow admins for some_feature:
8
8
  # Arturo::Feature.whitelist(:some_feature) do |user|
9
9
  # user.is_admin?
10
10
  # end
11
11
  #
12
- # # disallow for small accounts:
12
+ # # disallow for small accounts for another_feature:
13
13
  # Arturo::Feature.blacklist(:another_feature) do |user|
14
14
  # user.account.small?
15
15
  # end
16
16
  #
17
+ # # allow large accounts access to large features:
18
+ # Arturo::Feature.whitelist do |feature, user|
19
+ # feature.symbol.to_s =~ /^large/ && user.account.large?
20
+ # end
21
+ #
17
22
  # Blacklists and whitelists can be defined before the feature exists
18
23
  # and are not persisted, so they are best defined in initializers.
19
24
  # This is particularly important if your application runs in several
@@ -25,21 +30,32 @@ module Arturo
25
30
  end
26
31
 
27
32
  module ClassMethods
33
+
28
34
  def whitelists
29
- @whitelists ||= {}
35
+ @whitelists ||= []
30
36
  end
31
37
 
32
38
  def blacklists
33
- @blacklists ||= {}
39
+ @blacklists ||= []
34
40
  end
35
41
 
36
- def whitelist(feature_symbol, &block)
37
- whitelists[feature_symbol.to_sym] = block
42
+ def whitelist(feature_symbol = nil, &block)
43
+ whitelists << two_arg_block(feature_symbol, block)
38
44
  end
39
45
 
40
- def blacklist(feature_symbol, &block)
41
- blacklists[feature_symbol.to_sym] = block
46
+ def blacklist(feature_symbol = nil, &block)
47
+ blacklists << two_arg_block(feature_symbol, block)
42
48
  end
49
+
50
+ private
51
+
52
+ def two_arg_block(symbol, block)
53
+ return block if symbol.nil?
54
+ lambda do |feature, recipient|
55
+ feature.symbol == symbol && block.call(recipient)
56
+ end
57
+ end
58
+
43
59
  end
44
60
 
45
61
  protected
@@ -52,9 +68,8 @@ module Arturo
52
68
  x_listed?(self.class.blacklists, feature_recipient)
53
69
  end
54
70
 
55
- def x_listed?(list_map, feature_recipient)
56
- list = list_map[self.symbol.to_sym]
57
- list.present? && list.call(feature_recipient)
71
+ def x_listed?(lists, feature_recipient)
72
+ lists.any? { |block| block.call(self, feature_recipient) }
58
73
  end
59
74
 
60
75
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arturo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,7 +37,7 @@ cert_chain:
37
37
  eExwbFhYR2tTdDNOUzhSRmhRRkNPSWRnc1hFbGpFdlpwVnh1cmk1T2JIMHpx
38
38
  eFVOWE9scQo1bEVpNTZuM0tra0tSaHUxY0U2MWdBPT0KLS0tLS1FTkQgQ0VS
39
39
  VElGSUNBVEUtLS0tLQo=
40
- date: 2013-05-01 00:00:00.000000000 Z
40
+ date: 2013-05-02 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rails
metadata.gz.sig CHANGED
Binary file