togls 3.0.0.pre.rc.5 → 3.0.0.pre.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/lib/togls/null_toggle.rb +0 -1
- data/lib/togls/rule.rb +3 -6
- data/lib/togls/rule_manager.rb +2 -2
- data/lib/togls/rule_repository.rb +8 -6
- data/lib/togls/rule_repository_drivers/env_override_driver.rb +6 -6
- data/lib/togls/rules/boolean.rb +3 -3
- data/lib/togls/toggle.rb +1 -1
- data/lib/togls/toggle_registry.rb +1 -9
- data/lib/togls/toggle_repository.rb +9 -29
- data/lib/togls/toggle_repository_drivers/env_override_driver.rb +2 -6
- data/lib/togls/toggle_repository_drivers/in_memory_driver.rb +0 -8
- data/lib/togls/toggler.rb +2 -2
- data/lib/togls/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: 2ee73b04334051fd4cfa74b24dd639181dd80433
|
4
|
+
data.tar.gz: a28ffbf8cfa7968d31d755f250ba287f3ec4ad05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d9044189ee0e1ea1f19ce740da3bef438f01d4e0ae8b462b72d0a25eaa0db6cfc5f4c71efced54b2e4d2d3aa8aa5fc6486beb525575b26cfb69f4b59f9ab99
|
7
|
+
data.tar.gz: ee82fe7033ff9de9b91e062ff395886b8167897f0853d25bc8448ef92f6d3c45eece901478cceb1f88014b2264e01535022eb937b9ee7df9668b37e116a8f0dd
|
data/CHANGELOG.md
CHANGED
@@ -10,6 +10,7 @@ that you can set version constraints properly.
|
|
10
10
|
|
11
11
|
#### [Unreleased] - now
|
12
12
|
|
13
|
+
* `Changed`: Rules to be identified by an abstract given string id
|
13
14
|
* `Changed`: Rule and Rule Type management to be global under Togls
|
14
15
|
* `Changed`: The testing interface to allow for contract enforcement in tests
|
15
16
|
and allow altering existing feature rules within tests.
|
data/lib/togls/null_toggle.rb
CHANGED
data/lib/togls/rule.rb
CHANGED
@@ -4,7 +4,7 @@ module Togls
|
|
4
4
|
# The Rule is an abstract base class that is intended to act as an interface
|
5
5
|
# for other rules to be implemented against.
|
6
6
|
class Rule
|
7
|
-
attr_reader :data, :type_id
|
7
|
+
attr_reader :data, :type_id, :id
|
8
8
|
|
9
9
|
def self.title
|
10
10
|
raise Togls::NotImplemented, "Rule type title not implemented"
|
@@ -18,7 +18,8 @@ module Togls
|
|
18
18
|
Togls::TargetTypes::NOT_SET
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET)
|
21
|
+
def initialize(id, type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET)
|
22
|
+
@id = id
|
22
23
|
@type_id = type_id
|
23
24
|
@data = data
|
24
25
|
@target_type = target_type
|
@@ -29,10 +30,6 @@ module Togls
|
|
29
30
|
raise Togls::NotImplemented, "Rule's #run method must be implemented"
|
30
31
|
end
|
31
32
|
|
32
|
-
def id
|
33
|
-
Togls::Helpers.sha1(@type_id, @data, target_type)
|
34
|
-
end
|
35
|
-
|
36
33
|
def target_type
|
37
34
|
return @target_type if @target_type && @target_type != Togls::TargetTypes::NOT_SET
|
38
35
|
return self.class.target_type unless self.class.target_type.nil?
|
data/lib/togls/rule_manager.rb
CHANGED
@@ -14,8 +14,8 @@ module Togls
|
|
14
14
|
rule_type_registry.get(type_id)
|
15
15
|
end
|
16
16
|
|
17
|
-
def rule(type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET)
|
18
|
-
rule_type(type_id).new(type_id, data, target_type: target_type)
|
17
|
+
def rule(id, type_id, data = nil, target_type: Togls::TargetTypes::NOT_SET)
|
18
|
+
rule_type(type_id).new(id, type_id, data, target_type: target_type)
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
@@ -18,14 +18,15 @@ module Togls
|
|
18
18
|
def store(rule)
|
19
19
|
rule_data = extract_storage_payload(rule)
|
20
20
|
@drivers.each do |driver|
|
21
|
-
driver.store(rule.id, rule_data)
|
21
|
+
driver.store(rule.id.to_s, rule_data)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def extract_storage_payload(rule)
|
26
26
|
{
|
27
|
+
'id' => rule.id.to_s,
|
27
28
|
'type_id' => ::Togls.send(:rule_type_registry).get_type_id(rule.class.to_s),
|
28
|
-
'data' => rule.data,
|
29
|
+
'data' => rule.data,
|
29
30
|
'target_type' => rule.target_type.to_s
|
30
31
|
}
|
31
32
|
end
|
@@ -51,14 +52,14 @@ module Togls
|
|
51
52
|
raise Togls::RepositoryRuleDataInvalid, "None of the rule repository drivers claim to have the rule"
|
52
53
|
end
|
53
54
|
|
54
|
-
['type_id', 'data', 'target_type'].each do |k|
|
55
|
+
['id', 'type_id', 'data', 'target_type'].each do |k|
|
55
56
|
if !rule_data.has_key? k
|
56
57
|
Togls.logger.debug "One of the rule repository drivers returned rule data that is missing the '#{k}'"
|
57
58
|
raise Togls::RepositoryRuleDataInvalid, "One of the rule repository drivers returned rule data that is missing the '#{k}'"
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
['type_id', 'target_type'].each do |k|
|
62
|
+
['id', 'type_id', 'target_type'].each do |k|
|
62
63
|
if !rule_data[k].is_a?(String)
|
63
64
|
Togls.logger.debug "One of the rule repository drivers returned rule data with '#{k}' not being a string"
|
64
65
|
raise Togls::RepositoryRuleDataInvalid, "One of the rule repository drivers returned rule data with '#{k}' not being a string"
|
@@ -69,10 +70,11 @@ module Togls
|
|
69
70
|
def reconstitute_rule(rule_data)
|
70
71
|
if rule_data.has_key?('target_type')
|
71
72
|
::Togls.rule_type(rule_data['type_id'])\
|
72
|
-
.new(rule_data['type_id'].to_sym, rule_data['data'],
|
73
|
+
.new(rule_data['id'].to_sym, rule_data['type_id'].to_sym, rule_data['data'],
|
73
74
|
target_type: rule_data['target_type'].to_sym)
|
74
75
|
else
|
75
|
-
::Togls.rule_type(rule_data['type_id']).new(rule_data['
|
76
|
+
::Togls.rule_type(rule_data['type_id']).new(rule_data['id'].to_sym,
|
77
|
+
rule_data['type_id'].to_sym,
|
76
78
|
rule_data['data'])
|
77
79
|
end
|
78
80
|
end
|
@@ -9,12 +9,12 @@ module Togls
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def get(rule_id)
|
12
|
-
boolean_false = Togls::Rules::Boolean.new(:boolean, false)
|
13
|
-
boolean_true = Togls::Rules::Boolean.new(:boolean, true)
|
14
|
-
if rule_id == boolean_true.id
|
15
|
-
return { 'type_id' => 'boolean', 'data' => true, 'target_type' => Togls::TargetTypes::NONE.to_s }
|
16
|
-
elsif rule_id == boolean_false.id
|
17
|
-
return { 'type_id' => 'boolean', 'data' => false, 'target_type' => Togls::TargetTypes::NONE.to_s }
|
12
|
+
boolean_false = Togls::Rules::Boolean.new(:off, :boolean, false)
|
13
|
+
boolean_true = Togls::Rules::Boolean.new(:on, :boolean, true)
|
14
|
+
if rule_id == boolean_true.id.to_s
|
15
|
+
return { 'id' => 'on', 'type_id' => 'boolean', 'data' => true, 'target_type' => Togls::TargetTypes::NONE.to_s }
|
16
|
+
elsif rule_id == boolean_false.id.to_s
|
17
|
+
return { 'id' => 'off', 'type_id' => 'boolean', 'data' => false, 'target_type' => Togls::TargetTypes::NONE.to_s }
|
18
18
|
else
|
19
19
|
nil
|
20
20
|
end
|
data/lib/togls/rules/boolean.rb
CHANGED
@@ -6,7 +6,7 @@ module Togls
|
|
6
6
|
# it's initialization data and when evaluated determines the toggle state
|
7
7
|
# based on the initialization value. Example:
|
8
8
|
#
|
9
|
-
# always_on = Togls::Rules::Boolean.new(:boolean, true)
|
9
|
+
# always_on = Togls::Rules::Boolean.new(:on, :boolean, true)
|
10
10
|
# Togls.features do
|
11
11
|
# feature(:foo).on(always_on)
|
12
12
|
# end
|
@@ -25,9 +25,9 @@ The Boolean rule type is the base line rule for Togls. It allows you to
|
|
25
25
|
flag a feature on/off by specifing a boolean value as the initialization
|
26
26
|
data. For example:
|
27
27
|
|
28
|
-
Togls::Rules::Boolean.new(:boolean, true) # rule that always evaluates to on
|
28
|
+
Togls::Rules::Boolean.new(:on, :boolean, true) # rule that always evaluates to on
|
29
29
|
|
30
|
-
Togls::Rules::Boolean.new(:boolean, false) # rule that always evaluates to off
|
30
|
+
Togls::Rules::Boolean.new(:off, :boolean, false) # rule that always evaluates to off
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
data/lib/togls/toggle.rb
CHANGED
@@ -31,15 +31,7 @@ module Togls
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def get(key)
|
34
|
-
|
35
|
-
if toggle.is_a?(Togls::ToggleMissingToggle)
|
36
|
-
Togls.logger.warn("Feature identified by '#{key}' has not been defined")
|
37
|
-
end
|
38
|
-
toggle
|
39
|
-
end
|
40
|
-
|
41
|
-
def all
|
42
|
-
@toggle_repository.all
|
34
|
+
@toggle_repository.get(key.to_s)
|
43
35
|
end
|
44
36
|
end
|
45
37
|
end
|
@@ -25,13 +25,18 @@ module Togls
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def extract_storage_payload(toggle)
|
28
|
-
{ 'feature_id' => toggle.feature.id, 'rule_id' => toggle.rule.id }
|
28
|
+
{ 'feature_id' => toggle.feature.id, 'rule_id' => toggle.rule.id.to_s }
|
29
29
|
end
|
30
30
|
|
31
31
|
def get(id)
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
@drivers.reverse.each do |driver|
|
33
|
+
toggle_data = driver.get(id)
|
34
|
+
if toggle_data
|
35
|
+
toggle = reconstitute_toggle(toggle_data)
|
36
|
+
return toggle unless toggle.is_a?(::Togls::NullToggle)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
Togls::NullToggle.new
|
35
40
|
end
|
36
41
|
|
37
42
|
def reconstitute_toggle(toggle_data)
|
@@ -56,30 +61,5 @@ module Togls
|
|
56
61
|
return Togls::RuleFeatureMismatchToggle.new
|
57
62
|
end
|
58
63
|
end
|
59
|
-
|
60
|
-
def fetch_toggle_data(id)
|
61
|
-
toggle_data = nil
|
62
|
-
@drivers.reverse.each do |driver|
|
63
|
-
toggle_data = driver.get(id)
|
64
|
-
break if toggle_data
|
65
|
-
end
|
66
|
-
toggle_data
|
67
|
-
end
|
68
|
-
|
69
|
-
def fetch_all_toggle_data
|
70
|
-
toggle_data_collection = {}
|
71
|
-
@drivers.each do |driver|
|
72
|
-
toggle_data_collection.merge!(driver.all)
|
73
|
-
end
|
74
|
-
toggle_data_collection
|
75
|
-
end
|
76
|
-
|
77
|
-
def all
|
78
|
-
toggle_data_collection = fetch_all_toggle_data.values
|
79
|
-
|
80
|
-
toggle_data_collection.map do |toggle_data|
|
81
|
-
reconstitute_toggle(toggle_data)
|
82
|
-
end
|
83
|
-
end
|
84
64
|
end
|
85
65
|
end
|
@@ -23,19 +23,15 @@ module Togls
|
|
23
23
|
return nil if ENV[toggle_env_key(toggle_id)].nil?
|
24
24
|
if ENV[toggle_env_key(toggle_id)] == 'true'
|
25
25
|
return { 'feature_id' => toggle_id, 'rule_id' =>
|
26
|
-
Togls::Rules::Boolean.new(:boolean, true).id }
|
26
|
+
Togls::Rules::Boolean.new(:on, :boolean, true).id.to_s }
|
27
27
|
elsif ENV[toggle_env_key(toggle_id)] == 'false'
|
28
28
|
return { 'feature_id' => toggle_id, 'rule_id' =>
|
29
|
-
Togls::Rules::Boolean.new(:boolean, false).id }
|
29
|
+
Togls::Rules::Boolean.new(:off, :boolean, false).id.to_s }
|
30
30
|
else
|
31
31
|
return nil
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def all
|
36
|
-
{}
|
37
|
-
end
|
38
|
-
|
39
35
|
private
|
40
36
|
|
41
37
|
def toggle_env_key(toggle_id)
|
data/lib/togls/toggler.rb
CHANGED
@@ -14,14 +14,14 @@ module Togls
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def on(rule = nil)
|
17
|
-
rule = Togls::Rules::Boolean.new(:boolean, true) if rule.nil?
|
17
|
+
rule = Togls::Rules::Boolean.new(:on, :boolean, true) if rule.nil?
|
18
18
|
@toggle.rule = rule
|
19
19
|
@toggle_repository.store(@toggle)
|
20
20
|
@toggle
|
21
21
|
end
|
22
22
|
|
23
23
|
def off
|
24
|
-
rule = Togls::Rules::Boolean.new(:boolean, false)
|
24
|
+
rule = Togls::Rules::Boolean.new(:off, :boolean, false)
|
25
25
|
@toggle.rule = rule
|
26
26
|
@toggle_repository.store(@toggle)
|
27
27
|
@toggle
|
data/lib/togls/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: togls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.pre.rc.
|
4
|
+
version: 3.0.0.pre.rc.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Miller
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-06-
|
13
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|