fflags 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +76 -0
- data/lib/fflags.rb +35 -0
- data/lib/fflags/configuration.rb +2 -1
- data/lib/fflags/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: d4473f7c614ad41d5c5e4d2e1df559278c20a200
|
4
|
+
data.tar.gz: 6b61fdfd07f57f0a580a4b51d74f9a028e95e6ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0a4880777a7f39c28b1dfa8b9148a336289e1d75414e115d9f3317c19250d6cfe3e65b06c35366f8ecba0205cff072837ef60b52ca42bc11ba384c2569c3b55
|
7
|
+
data.tar.gz: a3b7fc42322093bedfb9ae164fabb37f47eda40951ef7a6ba6805cb2b91710c92ea5e9b3f64824a830c9081e4a4d0e89ce5369633adbe1b15b1db0e2c4e63e35
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -87,6 +87,82 @@ FFlags.reset
|
|
87
87
|
FFlags.all
|
88
88
|
```
|
89
89
|
|
90
|
+
## To use in Rails
|
91
|
+
|
92
|
+
- Add the gem in Gemfile.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# Gemfile.rb
|
96
|
+
|
97
|
+
gem 'fflags'
|
98
|
+
```
|
99
|
+
|
100
|
+
- Add the initializer.
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
# config/initializer/fflags.rb
|
104
|
+
|
105
|
+
FFlags.config do |config|
|
106
|
+
config.flags = { new_feature: true }
|
107
|
+
..
|
108
|
+
end
|
109
|
+
```
|
110
|
+
|
111
|
+
- Use the feature anywhere in your code.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
if FFlags.new_feature?
|
115
|
+
puts 'Enabled'
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
## Template
|
120
|
+
|
121
|
+
Sometimes you need to set a set of flags in 1 go. Ex. Staging to have an exact same flag configuration as in Production.
|
122
|
+
You can use template for this.
|
123
|
+
|
124
|
+
Ex.
|
125
|
+
|
126
|
+
In the config,
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
FFlags.config do |config|
|
130
|
+
config.flags = { feature1: true, feature2: true, feature3: true }
|
131
|
+
config.templates = { production: { feature1: false, feature2: false, feature3: false } }
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
Then in your code,
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
FFlags.set_as_template(:production)
|
139
|
+
|
140
|
+
# To view all the templates
|
141
|
+
FFlags.templates
|
142
|
+
```
|
143
|
+
|
144
|
+
## Testing
|
145
|
+
|
146
|
+
Sometimes you need to test flag with different value in your test. You can set block for that.
|
147
|
+
|
148
|
+
Ex. in `rspec`
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
describe "#eat_tofu" do
|
152
|
+
context 'new feature enabled' do
|
153
|
+
FFlags.set(new_feature: true) do
|
154
|
+
# Do something
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'new feature disabled' do
|
159
|
+
FFlags.set(new_feature: false) do
|
160
|
+
# Do something
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
90
166
|
## Development
|
91
167
|
|
92
168
|
After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
|
data/lib/fflags.rb
CHANGED
@@ -20,6 +20,15 @@ module FFlags
|
|
20
20
|
api.load_flags
|
21
21
|
end
|
22
22
|
|
23
|
+
# Reset the whole config to the default values
|
24
|
+
#
|
25
|
+
# Ex.
|
26
|
+
# FFlags.reset_config
|
27
|
+
def reset_config
|
28
|
+
@configuration = nil
|
29
|
+
reset
|
30
|
+
end
|
31
|
+
|
23
32
|
# Returns all supported flags.
|
24
33
|
#
|
25
34
|
# Ex.
|
@@ -28,6 +37,32 @@ module FFlags
|
|
28
37
|
api.flags
|
29
38
|
end
|
30
39
|
|
40
|
+
# Returns all templates.
|
41
|
+
#
|
42
|
+
# Ex.
|
43
|
+
# FFlags.templates
|
44
|
+
def templates
|
45
|
+
configuration.templates
|
46
|
+
end
|
47
|
+
|
48
|
+
# Sets as given template.
|
49
|
+
# It will returns false if the template doesn't exists
|
50
|
+
#
|
51
|
+
# Ex.
|
52
|
+
# FFlags.set_as_template(:template_name)
|
53
|
+
def set_as_template(template)
|
54
|
+
template = templates[template.to_sym] || templates[template.to_s]
|
55
|
+
|
56
|
+
return false unless template
|
57
|
+
|
58
|
+
status = true
|
59
|
+
template.each_pair do |key, value|
|
60
|
+
status &&= set(key, value)
|
61
|
+
end
|
62
|
+
|
63
|
+
status
|
64
|
+
end
|
65
|
+
|
31
66
|
# Check if the flag is enabled,
|
32
67
|
# it returns true | false.
|
33
68
|
#
|
data/lib/fflags/configuration.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module FFlags
|
2
2
|
# Configuration Class
|
3
3
|
class Configuration
|
4
|
-
attr_accessor :key, :redis_url, :debug, :flags
|
4
|
+
attr_accessor :key, :redis_url, :debug, :flags, :templates
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
set_default_values
|
@@ -14,6 +14,7 @@ module FFlags
|
|
14
14
|
@redis_url = 'redis://127.0.0.1:6379'
|
15
15
|
@debug = false
|
16
16
|
@flags = {}
|
17
|
+
@templates = {}
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
data/lib/fflags/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fflags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Faizal Zakaria
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|