offs 1.2.0 → 1.3.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.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/offs/version.rb +1 -1
- data/lib/offs.rb +15 -0
- data/spec/offs_spec.rb +9 -0
- 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: c7db6d39408404296ef58f569ece95b32633ef09
|
4
|
+
data.tar.gz: 2eaa89d57e80b8c512819fcf96fe6bb562bb9ba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3996fa7d6619ba57aa666114d805a66f29c17fa4285c5223dcbe610d1c210d6d6c15192fd6382c67006caabe843525008ef9d0395dd4408acbabc89b7fc4557
|
7
|
+
data.tar.gz: 2f44320aed399e0a488f397e2ec8738e36fc627fff2e33536870c08efcc44cec361d8dcb9e856c53082339deb7afef48c38c7a6b90a05ce75ee5ca9070c09e2c
|
data/README.md
CHANGED
@@ -76,12 +76,20 @@ class Foo
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
def do_something_for_new_feature
|
81
|
+
OFFS.raise_error_unless_we :use_my_million_dollar_idea
|
82
|
+
# The following code will only be reached if the feature is enabled.
|
83
|
+
# Otherwise we raise an OFFS::FeatureDisabled error
|
84
|
+
end
|
79
85
|
end
|
80
86
|
```
|
81
87
|
|
82
88
|
Note that you are not required to have *both* the `would_like_to` and
|
83
89
|
`may_still_need_to` blocks present; they simply become a noop if not
|
84
|
-
present.
|
90
|
+
present. Shortcuts for this usage are provided via
|
91
|
+
`OFFS.if_you_would_like_to` and `OFFS.if_you_do_not_want_to`,
|
92
|
+
respectively.
|
85
93
|
|
86
94
|
## Contributing
|
87
95
|
|
data/lib/offs/version.rb
CHANGED
data/lib/offs.rb
CHANGED
@@ -5,6 +5,8 @@ require 'injectable_dependencies'
|
|
5
5
|
class OFFS
|
6
6
|
include InjectableDependencies
|
7
7
|
|
8
|
+
class FeatureDisabled < RuntimeError; end
|
9
|
+
|
8
10
|
class << self
|
9
11
|
def so_you_want_to(flag, &block)
|
10
12
|
new(flag).so_you_want_to(&block)
|
@@ -22,6 +24,10 @@ class OFFS
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
def raise_error_unless_we(flag)
|
28
|
+
new(flag).raise_error_unless_we
|
29
|
+
end
|
30
|
+
|
25
31
|
def feature_flags
|
26
32
|
Flags.instance.to_a
|
27
33
|
end
|
@@ -47,6 +53,14 @@ class OFFS
|
|
47
53
|
when_flag(false, &block)
|
48
54
|
end
|
49
55
|
|
56
|
+
def raise_error_unless_we
|
57
|
+
unless flag_enabled?
|
58
|
+
raise FeatureDisabled,
|
59
|
+
"Attempted to access code that is only available when the '#{flag}' " \
|
60
|
+
+ "feature is enabled, and it is currenlty disabled."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
50
64
|
private
|
51
65
|
|
52
66
|
attr_reader :flag
|
@@ -59,6 +73,7 @@ class OFFS
|
|
59
73
|
def flag_status
|
60
74
|
feature_flags.enabled?(flag)
|
61
75
|
end
|
76
|
+
alias_method :flag_enabled?, :flag_status
|
62
77
|
|
63
78
|
def flag=(new_flag)
|
64
79
|
@flag = feature_flags.validate!(new_flag)
|
data/spec/offs_spec.rb
CHANGED
@@ -80,6 +80,10 @@ describe OFFS do
|
|
80
80
|
end
|
81
81
|
expect(x).to be_nil
|
82
82
|
end
|
83
|
+
|
84
|
+
it 'noops for raise_error_unless_we' do
|
85
|
+
OFFS.raise_error_unless_we(:my_cool_new_feature)
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
context "and the feature is turned off by default" do
|
@@ -115,6 +119,11 @@ describe OFFS do
|
|
115
119
|
end
|
116
120
|
expect(x).to eq 1
|
117
121
|
end
|
122
|
+
|
123
|
+
it 'raises an OFFS::FeatureDisabled error for raise_error_unless_we' do
|
124
|
+
expect { OFFS.raise_error_unless_we(:my_cool_new_feature) }.to \
|
125
|
+
raise_error(OFFS::FeatureDisabled, /my_cool_new_feature/)
|
126
|
+
end
|
118
127
|
end
|
119
128
|
end
|
120
129
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: offs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wilger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: injectable_dependencies
|