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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fc3fda9bba9167cddbb98a303939e34afd02bfb
4
- data.tar.gz: fb86663e91208f86cb779f54e6f33e76bca378bd
3
+ metadata.gz: d4473f7c614ad41d5c5e4d2e1df559278c20a200
4
+ data.tar.gz: 6b61fdfd07f57f0a580a4b51d74f9a028e95e6ed
5
5
  SHA512:
6
- metadata.gz: c7257ecf830e6eb41c8c3fe21087c94c09a794e9bad4235c1ee0f12f857789e0b053199f67f3b20ef1a44674b5a7f0c00af851881db73eefedf535297747ff38
7
- data.tar.gz: 07d5ddca50a961399945aed7e235ecd22c8f26765880a172ba2d2ed143c9c9525d60ebb59e38af297b16eacb9a641095614143981e675e31e1961eef946b9c73
6
+ metadata.gz: b0a4880777a7f39c28b1dfa8b9148a336289e1d75414e115d9f3317c19250d6cfe3e65b06c35366f8ecba0205cff072837ef60b52ca42bc11ba384c2569c3b55
7
+ data.tar.gz: a3b7fc42322093bedfb9ae164fabb37f47eda40951ef7a6ba6805cb2b91710c92ea5e9b3f64824a830c9081e4a4d0e89ce5369633adbe1b15b1db0e2c4e63e35
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fflags (0.4.2)
4
+ fflags (0.4.3)
5
5
  redis (>= 3.0.0)
6
6
 
7
7
  GEM
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.
@@ -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
  #
@@ -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
@@ -1,3 +1,3 @@
1
1
  module FFlags
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.4.3'.freeze
3
3
  end
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.2
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-07 00:00:00.000000000 Z
11
+ date: 2018-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis