feature_cop 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/feature_cop.gemspec +3 -1
- data/lib/feature_cop.rb +8 -30
- data/lib/feature_cop/blacklist.rb +12 -7
- data/lib/feature_cop/sampling.rb +28 -0
- data/lib/feature_cop/toggle.rb +19 -0
- data/lib/feature_cop/version.rb +1 -1
- data/lib/feature_cop/whitelist.rb +11 -6
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e64328ea3e26327deed78d769835ef6e42e79c88
|
4
|
+
data.tar.gz: 9fe68fe7b951160df830506f39cb387f5b0ddcc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8c81a16efe3790b2de4357ea07389db1fe40a68eca74939b75e7e9ca83f475b36835651e03c076cdf14448b0689200ff2ff0f4e4a432a423cd7fbfabb97bca2
|
7
|
+
data.tar.gz: c8f2cee524a7b19c38997b688d6436ef46ebd2a35c32b56970dbb746157d6b6ec3db1172e8e4f1603cacf89d5c95bca4e52e021efcc086858d63c98a56439262
|
data/feature_cop.gemspec
CHANGED
@@ -14,13 +14,15 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "http://www.github.com/nuvi/feature_cop"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
+
spec.required_ruby_version = '> 2.0.0'
|
18
|
+
|
17
19
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
20
|
spec.bindir = "exe"
|
19
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
22
|
spec.require_paths = ["lib"]
|
21
23
|
|
22
24
|
spec.add_dependency 'activesupport', '~> 4.2'
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
24
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
27
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
28
|
end
|
data/lib/feature_cop.rb
CHANGED
@@ -5,6 +5,8 @@ require "feature_cop/version"
|
|
5
5
|
require "feature_cop/enumerable_extensions"
|
6
6
|
require "feature_cop/whitelist"
|
7
7
|
require "feature_cop/blacklist"
|
8
|
+
require "feature_cop/sampling"
|
9
|
+
require "feature_cop/toggle"
|
8
10
|
require "json"
|
9
11
|
require "yaml"
|
10
12
|
|
@@ -13,19 +15,13 @@ require "yaml"
|
|
13
15
|
module FeatureCop
|
14
16
|
include FeatureCop::Whitelist
|
15
17
|
include FeatureCop::Blacklist
|
18
|
+
include FeatureCop::Sampling
|
19
|
+
include FeatureCop::Toggle
|
16
20
|
|
17
|
-
def self.allows?(feature, identifier = nil,
|
21
|
+
def self.allows?(feature, identifier = nil, options = {})
|
18
22
|
feature_status = ENV["#{feature.to_s.upcase}"]
|
19
23
|
return false if feature_status.nil?
|
20
|
-
self.method(feature_status.downcase).call(identifier)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.enabled(identifier)
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.disabled(identifier)
|
28
|
-
false
|
24
|
+
self.method(feature_status.downcase).call(feature.to_s, identifier.to_s, options)
|
29
25
|
end
|
30
26
|
|
31
27
|
def self.env
|
@@ -40,24 +36,6 @@ module FeatureCop
|
|
40
36
|
@features = self.set_features
|
41
37
|
end
|
42
38
|
|
43
|
-
def self.sample10(identifier)
|
44
|
-
return true if whitelisted?(identifier)
|
45
|
-
return false if blacklisted?(identifier)
|
46
|
-
identifier.bytes.sum % 10 == 0
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.sample30(identifier)
|
50
|
-
return true if whitelisted?(identifier)
|
51
|
-
return false if blacklisted?(identifier)
|
52
|
-
identifier.bytes.sum % 3 == 0
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.sample50(identifier)
|
56
|
-
return true if whitelisted?(identifier)
|
57
|
-
return false if blacklisted?(identifier)
|
58
|
-
identifier.bytes.sum.odd?
|
59
|
-
end
|
60
|
-
|
61
39
|
def self.set_features
|
62
40
|
features = {}
|
63
41
|
ENV.each_pair do |key, value|
|
@@ -68,8 +46,8 @@ module FeatureCop
|
|
68
46
|
|
69
47
|
def self.as_json(identifier = nil)
|
70
48
|
feature_set = {}
|
71
|
-
features.each_pair do |
|
72
|
-
feature_set[
|
49
|
+
features.each_pair do |feature, setting|
|
50
|
+
feature_set[feature.downcase.camelize(:lower)] = self.method(setting.downcase).call(feature, identifier)
|
73
51
|
end
|
74
52
|
feature_set
|
75
53
|
end
|
@@ -18,22 +18,27 @@ module FeatureCop
|
|
18
18
|
self.blacklist = ::YAML.load_file(absolute_path)[env]
|
19
19
|
end
|
20
20
|
|
21
|
-
def all_except_blacklist(identifier)
|
22
|
-
return true if
|
23
|
-
!blacklisted?(identifier)
|
21
|
+
def all_except_blacklist(feature, identifier, options = {})
|
22
|
+
return true if blacklist.nil?
|
23
|
+
!blacklisted?(feature, identifier, options)
|
24
24
|
end
|
25
25
|
|
26
26
|
def blacklist
|
27
|
-
@blacklist
|
27
|
+
@blacklist ||= {}
|
28
28
|
end
|
29
29
|
|
30
30
|
def blacklist=(blacklist)
|
31
|
+
if blacklist.is_a?(Array)
|
32
|
+
@blacklist = { "default" => blacklist }
|
33
|
+
return
|
34
|
+
end
|
31
35
|
@blacklist = blacklist
|
32
36
|
end
|
33
37
|
|
34
|
-
def blacklisted?(identifier)
|
35
|
-
|
36
|
-
|
38
|
+
def blacklisted?(feature, identifier, options = {})
|
39
|
+
feature = "default" if blacklist[feature].nil?
|
40
|
+
return false if blacklist[feature].nil?
|
41
|
+
blacklist[feature].include?(identifier)
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FeatureCop
|
2
|
+
module Sampling
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def sample10(feature, identifier, options = {})
|
10
|
+
return true if whitelisted?(feature, identifier, options)
|
11
|
+
return false if blacklisted?(feature, identifier, options)
|
12
|
+
identifier.bytes.sum % 10 == 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def sample30(feature, identifier, options = {})
|
16
|
+
return true if whitelisted?(feature, identifier, options)
|
17
|
+
return false if blacklisted?(feature, identifier, options)
|
18
|
+
identifier.bytes.sum % 3 == 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def sample50(feature, identifier, options = {})
|
22
|
+
return true if whitelisted?(feature, identifier, options)
|
23
|
+
return false if blacklisted?(feature, identifier, options)
|
24
|
+
identifier.bytes.sum.odd?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/feature_cop/version.rb
CHANGED
@@ -19,20 +19,25 @@ module FeatureCop
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def whitelist
|
22
|
-
@whitelist
|
22
|
+
@whitelist ||= {}
|
23
23
|
end
|
24
24
|
|
25
25
|
def whitelist=(whitelist)
|
26
|
+
if whitelist.is_a?(Array)
|
27
|
+
@whitelist = { "default" => whitelist }
|
28
|
+
return
|
29
|
+
end
|
26
30
|
@whitelist = whitelist
|
27
31
|
end
|
28
32
|
|
29
|
-
def whitelist_only(identifier)
|
30
|
-
whitelisted?(identifier)
|
33
|
+
def whitelist_only(feature, identifier, options = {})
|
34
|
+
whitelisted?(feature, identifier, options)
|
31
35
|
end
|
32
36
|
|
33
|
-
def whitelisted?(identifier)
|
34
|
-
|
35
|
-
|
37
|
+
def whitelisted?(feature, identifier, options = {})
|
38
|
+
feature = "default" if whitelist[feature].nil?
|
39
|
+
return false if whitelist[feature].nil?
|
40
|
+
whitelist[feature].include?(identifier)
|
36
41
|
end
|
37
42
|
end
|
38
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature_cop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Allred
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.9'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.9'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +86,8 @@ files:
|
|
86
86
|
- lib/feature_cop.rb
|
87
87
|
- lib/feature_cop/blacklist.rb
|
88
88
|
- lib/feature_cop/enumerable_extensions.rb
|
89
|
+
- lib/feature_cop/sampling.rb
|
90
|
+
- lib/feature_cop/toggle.rb
|
89
91
|
- lib/feature_cop/version.rb
|
90
92
|
- lib/feature_cop/whitelist.rb
|
91
93
|
homepage: http://www.github.com/nuvi/feature_cop
|
@@ -98,9 +100,9 @@ require_paths:
|
|
98
100
|
- lib
|
99
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
102
|
requirements:
|
101
|
-
- - "
|
103
|
+
- - ">"
|
102
104
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
105
|
+
version: 2.0.0
|
104
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
107
|
requirements:
|
106
108
|
- - ">="
|