flipper 0.10.2 → 0.11.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +42 -0
  3. data/.rubocop_todo.yml +188 -0
  4. data/Changelog.md +10 -0
  5. data/Gemfile +6 -3
  6. data/README.md +4 -3
  7. data/Rakefile +13 -13
  8. data/docs/Adapters.md +2 -1
  9. data/docs/DockerCompose.md +6 -3
  10. data/docs/Gates.md +25 -3
  11. data/docs/Optimization.md +27 -5
  12. data/docs/api/README.md +73 -32
  13. data/docs/http/README.md +34 -0
  14. data/docs/read-only/README.md +22 -0
  15. data/examples/percentage_of_actors_group.rb +49 -0
  16. data/flipper.gemspec +15 -15
  17. data/lib/flipper.rb +2 -5
  18. data/lib/flipper/adapter.rb +10 -0
  19. data/lib/flipper/adapters/http.rb +147 -0
  20. data/lib/flipper/adapters/http/client.rb +83 -0
  21. data/lib/flipper/adapters/http/error.rb +14 -0
  22. data/lib/flipper/adapters/instrumented.rb +36 -36
  23. data/lib/flipper/adapters/memoizable.rb +2 -6
  24. data/lib/flipper/adapters/memory.rb +10 -9
  25. data/lib/flipper/adapters/operation_logger.rb +1 -1
  26. data/lib/flipper/adapters/pstore.rb +12 -11
  27. data/lib/flipper/adapters/read_only.rb +6 -6
  28. data/lib/flipper/dsl.rb +1 -3
  29. data/lib/flipper/feature.rb +11 -16
  30. data/lib/flipper/gate.rb +3 -3
  31. data/lib/flipper/gate_values.rb +6 -6
  32. data/lib/flipper/gates/group.rb +2 -2
  33. data/lib/flipper/gates/percentage_of_actors.rb +2 -2
  34. data/lib/flipper/instrumentation/log_subscriber.rb +2 -4
  35. data/lib/flipper/instrumentation/metriks.rb +1 -1
  36. data/lib/flipper/instrumentation/statsd.rb +1 -1
  37. data/lib/flipper/instrumentation/statsd_subscriber.rb +1 -3
  38. data/lib/flipper/instrumentation/subscriber.rb +11 -10
  39. data/lib/flipper/instrumenters/memory.rb +1 -5
  40. data/lib/flipper/instrumenters/noop.rb +1 -1
  41. data/lib/flipper/middleware/memoizer.rb +11 -27
  42. data/lib/flipper/middleware/setup_env.rb +44 -0
  43. data/lib/flipper/registry.rb +8 -10
  44. data/lib/flipper/spec/shared_adapter_specs.rb +45 -67
  45. data/lib/flipper/test/shared_adapter_test.rb +25 -31
  46. data/lib/flipper/typecast.rb +2 -2
  47. data/lib/flipper/types/actor.rb +2 -4
  48. data/lib/flipper/types/group.rb +1 -1
  49. data/lib/flipper/types/percentage.rb +2 -1
  50. data/lib/flipper/version.rb +1 -1
  51. data/spec/fixtures/feature.json +31 -0
  52. data/spec/flipper/adapters/http_spec.rb +148 -0
  53. data/spec/flipper/adapters/instrumented_spec.rb +20 -20
  54. data/spec/flipper/adapters/memoizable_spec.rb +59 -59
  55. data/spec/flipper/adapters/operation_logger_spec.rb +16 -16
  56. data/spec/flipper/adapters/pstore_spec.rb +6 -6
  57. data/spec/flipper/adapters/read_only_spec.rb +28 -34
  58. data/spec/flipper/dsl_spec.rb +73 -84
  59. data/spec/flipper/feature_check_context_spec.rb +27 -27
  60. data/spec/flipper/feature_spec.rb +186 -196
  61. data/spec/flipper/gate_spec.rb +11 -11
  62. data/spec/flipper/gate_values_spec.rb +46 -45
  63. data/spec/flipper/gates/actor_spec.rb +2 -2
  64. data/spec/flipper/gates/boolean_spec.rb +24 -23
  65. data/spec/flipper/gates/group_spec.rb +19 -19
  66. data/spec/flipper/gates/percentage_of_actors_spec.rb +10 -10
  67. data/spec/flipper/gates/percentage_of_time_spec.rb +2 -2
  68. data/spec/flipper/instrumentation/log_subscriber_spec.rb +20 -20
  69. data/spec/flipper/instrumentation/metriks_subscriber_spec.rb +20 -20
  70. data/spec/flipper/instrumentation/statsd_subscriber_spec.rb +11 -11
  71. data/spec/flipper/instrumenters/memory_spec.rb +5 -5
  72. data/spec/flipper/instrumenters/noop_spec.rb +6 -6
  73. data/spec/flipper/middleware/memoizer_spec.rb +83 -100
  74. data/spec/flipper/middleware/setup_env_spec.rb +76 -0
  75. data/spec/flipper/registry_spec.rb +35 -39
  76. data/spec/flipper/typecast_spec.rb +18 -18
  77. data/spec/flipper/types/actor_spec.rb +30 -29
  78. data/spec/flipper/types/boolean_spec.rb +8 -8
  79. data/spec/flipper/types/group_spec.rb +28 -28
  80. data/spec/flipper/types/percentage_spec.rb +14 -14
  81. data/spec/flipper_spec.rb +61 -54
  82. data/spec/helper.rb +26 -21
  83. data/spec/integration_spec.rb +121 -113
  84. data/spec/support/fake_udp_socket.rb +1 -1
  85. data/spec/support/spec_helpers.rb +32 -4
  86. data/test/adapters/pstore_test.rb +3 -3
  87. data/test/test_helper.rb +1 -1
  88. metadata +20 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: babc8ef94b2e4998e345e538272ce930a3fc8919
4
- data.tar.gz: 0fa3de8f4ab472e65bcf203fdaece22a44e481a6
3
+ metadata.gz: 1dba40ce57cd34d4be2608ce8725c2b314eb5345
4
+ data.tar.gz: 929230ec45235cfb08634d63ab0bdfe704197b45
5
5
  SHA512:
6
- metadata.gz: 2b12d5d3debc25773f9ffe0f07d1f58d13b1eaec384603d7cdf1b5d073a25c98d4c61364f94021d5ad017e3071810d1f91a4e69b865004246c8b3b53ff87cf96
7
- data.tar.gz: 1633e3e20e4ecb43673c438d1a45e54e35c438ac33f86e25337766b2ca0732f1052cc5dd48af17e2cf33315e5e15756b8a040861a243db93a73fe93d61e4dec0
6
+ metadata.gz: 3618c5c38a0901f219e719de7b04230ad8ca4534673f271b31c055fe1d88bb7545638b5bdb90c3fdec6e842819678e4137c2f32eb83eb77826381396eb75d95e
7
+ data.tar.gz: 98e939ae62ee4ac6bd7f19eab5be8c0c58281525db190a852a0b36643e8108c16feb5df94a4ca943ab4517bccec6c7a20d80ea5389fa7bb595bb7d7fdb394cf9
@@ -0,0 +1,42 @@
1
+ # This is the configuration used to check the rubocop source code.
2
+
3
+ require: rubocop-rspec
4
+ inherit_from:
5
+ - .rubocop_todo.yml
6
+
7
+ AllCops:
8
+ Exclude:
9
+ - 'docker-compose/**/*'
10
+ - 'examples/**/*'
11
+ - 'tmp/**/*'
12
+ - 'bin/**/*'
13
+ TargetRubyVersion: 2.0
14
+ # DefaultFormatter: fuubar
15
+ Style/Alias:
16
+ Enabled: false
17
+
18
+ Style/Documentation:
19
+ Enabled: false
20
+
21
+ Style/Encoding:
22
+ Enabled: false
23
+
24
+ Style/NumericLiterals:
25
+ Enabled: false
26
+
27
+ Style/StringLiterals:
28
+ Enabled: false
29
+
30
+ Metrics/LineLength:
31
+ Max: 100
32
+ Exclude:
33
+ - '*.gemspec'
34
+
35
+ Style/RegexpLiteral:
36
+ EnforcedStyle: mixed
37
+
38
+ Style/TrailingCommaInLiteral:
39
+ EnforcedStyleForMultiline: consistent_comma
40
+
41
+ RSpec/InstanceVariable:
42
+ Enabled: false
@@ -0,0 +1,188 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-11-20 15:49:33 +0000 using RuboCop version 0.45.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ require: rubocop-rspec
10
+
11
+ # Offense count: 2
12
+ Lint/AmbiguousRegexpLiteral:
13
+ Exclude:
14
+ - 'lib/flipper/instrumentation/metriks.rb'
15
+ - 'lib/flipper/instrumentation/statsd.rb'
16
+
17
+ # Offense count: 6
18
+ # Configuration parameters: AllowSafeAssignment.
19
+ Lint/AssignmentInCondition:
20
+ Exclude:
21
+ - 'lib/flipper/adapters/active_record.rb'
22
+ - 'lib/flipper/adapters/sequel.rb'
23
+ - 'lib/flipper/feature.rb'
24
+ - 'lib/flipper/gate_values.rb'
25
+
26
+ # Offense count: 1
27
+ Lint/Eval:
28
+ Exclude:
29
+ - 'flipper.gemspec'
30
+
31
+ # Offense count: 3
32
+ Lint/HandleExceptions:
33
+ Exclude:
34
+ - 'spec/flipper/adapters/mongo_spec.rb'
35
+ - 'test/adapters/mongo_test.rb'
36
+ - 'test/helper.rb'
37
+
38
+ # Offense count: 24
39
+ Lint/ShadowingOuterLocalVariable:
40
+ Exclude:
41
+ - 'lib/flipper/adapters/active_record.rb'
42
+ - 'lib/flipper/adapters/instrumented.rb'
43
+ - 'lib/flipper/adapters/sequel.rb'
44
+ - 'spec/flipper/api/v1/actions/actors_gate_spec.rb'
45
+ - 'spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb'
46
+ - 'spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb'
47
+ - 'spec/flipper/dsl_spec.rb'
48
+ - 'spec/flipper/feature_spec.rb'
49
+ - 'spec/flipper/types/group_spec.rb'
50
+
51
+ # Offense count: 26
52
+ Lint/UselessAssignment:
53
+ Exclude:
54
+ - 'lib/flipper/instrumentation/log_subscriber.rb'
55
+ - 'lib/flipper/instrumentation/subscriber.rb'
56
+ - 'lib/flipper/ui/actions/groups_gate.rb'
57
+ - 'spec/flipper/api/action_spec.rb'
58
+ - 'spec/flipper/dsl_spec.rb'
59
+ - 'spec/flipper/feature_spec.rb'
60
+ - 'spec/flipper/gates/group_spec.rb'
61
+ - 'spec/flipper/instrumentation/metriks_subscriber_spec.rb'
62
+ - 'spec/flipper/instrumentation/statsd_subscriber_spec.rb'
63
+ - 'spec/flipper_spec.rb'
64
+ - 'spec/flipper/middleware/memoizer_spec.rb'
65
+ - 'test/helper.rb'
66
+
67
+ # Offense count: 27
68
+ Metrics/AbcSize:
69
+ Max: 30
70
+
71
+ # Offense count: 1
72
+ # Configuration parameters: CountComments.
73
+ Metrics/BlockLength:
74
+ Max: 195
75
+
76
+ # Offense count: 4
77
+ # Configuration parameters: CountComments.
78
+ Metrics/ClassLength:
79
+ Max: 178
80
+
81
+ # Offense count: 39
82
+ # Configuration parameters: CountComments.
83
+ Metrics/MethodLength:
84
+ Max: 23
85
+
86
+ # Offense count: 65
87
+ # Configuration parameters: Max.
88
+ RSpec/ExampleLength:
89
+ Enabled: false
90
+
91
+ # Offense count: 2
92
+ # Configuration parameters: CustomTransform.
93
+ RSpec/FilePath:
94
+ Exclude:
95
+ - 'spec/flipper/adapters/pstore_spec.rb'
96
+ - 'spec/integration_spec.rb'
97
+
98
+ # Offense count: 91
99
+ RSpec/InstanceVariable:
100
+ Exclude:
101
+ - 'spec/flipper/adapters/operation_logger_spec.rb'
102
+ - 'spec/flipper/dsl_spec.rb'
103
+ - 'spec/flipper/feature_spec.rb'
104
+ - 'spec/flipper/instrumentation/log_subscriber_spec.rb'
105
+ - 'spec/flipper/ui/actions/add_feature_spec.rb'
106
+ - 'spec/flipper/ui/actions/features_spec.rb'
107
+ - 'spec/flipper/ui/decorators/feature_spec.rb'
108
+ - 'spec/flipper/ui/decorators/gate_spec.rb'
109
+ - 'spec/flipper/ui_spec.rb'
110
+ - 'spec/flipper_spec.rb'
111
+ - 'spec/integration_spec.rb'
112
+
113
+ # Offense count: 15
114
+ # Configuration parameters: IgnoreSymbolicNames.
115
+ RSpec/VerifiedDoubles:
116
+ Exclude:
117
+ - 'spec/flipper/api/v1/actions/features_spec.rb'
118
+ - 'spec/flipper/dsl_spec.rb'
119
+ - 'spec/flipper/feature_spec.rb'
120
+ - 'spec/flipper/types/group_spec.rb'
121
+ - 'spec/flipper_spec.rb'
122
+ - 'spec/integration_spec.rb'
123
+
124
+ # Offense count: 2
125
+ Style/AccessorMethodName:
126
+ Exclude:
127
+ - 'lib/flipper/adapters/memory.rb'
128
+ - 'lib/flipper/adapters/pstore.rb'
129
+
130
+ # Offense count: 7
131
+ Style/ConstantName:
132
+ Exclude:
133
+ - 'lib/flipper.rb'
134
+ - 'lib/flipper/adapters/dalli.rb'
135
+ - 'lib/flipper/adapters/memoizable.rb'
136
+ - 'lib/flipper/adapters/memory.rb'
137
+ - 'lib/flipper/adapters/mongo.rb'
138
+ - 'lib/flipper/adapters/pstore.rb'
139
+ - 'lib/flipper/adapters/redis.rb'
140
+
141
+ # Offense count: 3
142
+ Style/DoubleNegation:
143
+ Exclude:
144
+ - 'lib/flipper/adapters/memoizable.rb'
145
+ - 'lib/flipper/gates/boolean.rb'
146
+ - 'lib/flipper/typecast.rb'
147
+
148
+ # Offense count: 7
149
+ # Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
150
+ Style/FileName:
151
+ Exclude:
152
+ - 'lib/flipper-active_record.rb'
153
+ - 'lib/flipper-api.rb'
154
+ - 'lib/flipper-cloud.rb'
155
+ - 'lib/flipper-dalli.rb'
156
+ - 'lib/flipper-mongo.rb'
157
+ - 'lib/flipper-redis.rb'
158
+ - 'lib/flipper-sequel.rb'
159
+ - 'lib/flipper-ui.rb'
160
+
161
+ # Offense count: 2
162
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
163
+ # SupportedStyles: format, sprintf, percent
164
+ Style/FormatString:
165
+ Exclude:
166
+ - 'lib/flipper/instrumentation/log_subscriber.rb'
167
+
168
+ # Offense count: 10
169
+ # Configuration parameters: MinBodyLength.
170
+ Style/GuardClause:
171
+ Exclude:
172
+ - 'lib/flipper/api/v1/actions/percentage_of_actors_gate.rb'
173
+ - 'lib/flipper/api/v1/actions/percentage_of_time_gate.rb'
174
+ - 'lib/flipper/gate_values.rb'
175
+ - 'lib/flipper/instrumentation/statsd_subscriber.rb'
176
+ - 'lib/flipper/instrumentation/subscriber.rb'
177
+ - 'lib/flipper/registry.rb'
178
+ - 'lib/flipper/typecast.rb'
179
+
180
+ # Offense count: 1
181
+ Style/IfInsideElse:
182
+ Exclude:
183
+ - 'lib/flipper/gates/actor.rb'
184
+
185
+ # Offense count: 1
186
+ Style/MethodMissing:
187
+ Exclude:
188
+ - 'lib/flipper/types/actor.rb'
@@ -1,3 +1,13 @@
1
+ ## 0.11
2
+
3
+ * Use primary keys with sequel adapter (https://github.com/jnunemaker/flipper/pull/210).
4
+ * Add redis cache adapter (https://github.com/jnunemaker/flipper/pull/211).
5
+ * Finish API and HTTP adapter that speaks to API.
6
+ * Set flipper from env for API and UI (https://github.com/jnunemaker/flipper/pull/223 and https://github.com/jnunemaker/flipper/pull/229).
7
+ * Add flipper cloud adapter (https://github.com/jnunemaker/flipper/pull/249).
8
+ * Allow unregistered groups (https://github.com/jnunemaker/flipper/pull/244).
9
+ * Drop support for Ruby 2.0 as it is end of lined (https://github.com/jnunemaker/flipper/commit/c2c81ed89938155ce91acb5173ac38580f630e3d).
10
+
1
11
  ## 0.10.2
2
12
 
3
13
  * Add Adapter#get_multi to allow for efficient loading of more than one feature at a time (https://github.com/jnunemaker/flipper/pull/198)
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source 'https://rubygems.org'
2
- gemspec :name => 'flipper'
2
+ gemspec name: 'flipper'
3
3
 
4
4
  Dir['flipper-*.gemspec'].each do |gemspec|
5
5
  plugin = gemspec.scan(/flipper-(.*)\.gemspec/).flatten.first
6
- gemspec(:name => "flipper-#{plugin}", :development_group => plugin)
6
+ gemspec(name: "flipper-#{plugin}", development_group: plugin)
7
7
  end
8
8
 
9
9
  gem 'rake', '~> 10.4.2'
@@ -13,8 +13,11 @@ gem 'statsd-ruby', '~> 1.2.1'
13
13
  gem 'rspec', '~> 3.0'
14
14
  gem 'rack-test', '~> 0.6.3'
15
15
  gem 'sqlite3', '~> 1.3.11'
16
- gem 'rails', "~> #{ENV["RAILS_VERSION"] || '4.2.5'}"
16
+ gem 'rails', "~> #{ENV['RAILS_VERSION'] || '4.2.5'}"
17
17
  gem 'minitest', '~> 5.8.0'
18
+ gem 'rubocop', '~> 0.45.0'
19
+ gem 'rubocop-rspec', '= 1.5.1'
20
+ gem 'webmock', '~> 2.0'
18
21
 
19
22
  # for active support tests in test/ and only needed for ruby 2.2.x
20
23
  gem 'test-unit', '~> 3.0'
data/README.md CHANGED
@@ -80,9 +80,10 @@ Of course there are more [examples for you to peruse](examples/). You could also
80
80
 
81
81
  1. Fork it
82
82
  2. Create your feature branch (`git checkout -b my-new-feature`)
83
- 3. Commit your changes (`git commit -am 'Added some feature'`)
84
- 4. Push to the branch (`git push origin my-new-feature`)
85
- 5. Create new Pull Request
83
+ 3. Check your changes with Rubocop tests (`script/rubocop`)
84
+ 4. Commit your changes (`git commit -am 'Added some feature'`)
85
+ 5. Push to the branch (`git push origin my-new-feature`)
86
+ 6. Create new Pull Request
86
87
 
87
88
  ## Releasing
88
89
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env rake
2
- $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
3
  require 'rake/testtask'
4
- require "flipper/version"
4
+ require 'flipper/version'
5
5
 
6
6
  # gem install pkg/*.gem
7
7
  # gem uninstall flipper flipper-ui flipper-redis
@@ -16,34 +16,34 @@ task :build do
16
16
  end
17
17
 
18
18
  desc 'Tags version, pushes to remote, and pushes gem'
19
- task :release => :build do
19
+ task release: :build do
20
20
  sh 'git', 'tag', "v#{Flipper::VERSION}"
21
- sh "git push origin master"
21
+ sh 'git push origin master'
22
22
  sh "git push origin v#{Flipper::VERSION}"
23
- sh "ls pkg/*.gem | xargs -n 1 gem push"
23
+ sh 'ls pkg/*.gem | xargs -n 1 gem push'
24
24
  end
25
25
 
26
- require "rspec/core/rake_task"
26
+ require 'rspec/core/rake_task'
27
27
  RSpec::Core::RakeTask.new(:spec) do |t|
28
28
  t.rspec_opts = %w(--color)
29
29
  end
30
30
 
31
31
  namespace :spec do
32
- desc "Run specs for UI queue"
32
+ desc 'Run specs for UI queue'
33
33
  RSpec::Core::RakeTask.new(:ui) do |t|
34
34
  t.rspec_opts = %w(--color)
35
- t.pattern = ["spec/flipper/ui/**/*_spec.rb", "spec/flipper/ui_spec.rb"]
35
+ t.pattern = ['spec/flipper/ui/**/*_spec.rb', 'spec/flipper/ui_spec.rb']
36
36
  end
37
37
  end
38
38
 
39
39
  Rake::TestTask.new do |t|
40
- t.libs = ['lib', 'test']
41
- t.pattern = "test/**/*_test.rb"
40
+ t.libs = %w(lib test)
41
+ t.pattern = 'test/**/*_test.rb'
42
42
  end
43
43
 
44
44
  Rake::TestTask.new(:shared_test) do |t|
45
- t.libs = ['lib', 'test']
46
- t.pattern = "lib/flipper/shared/test/**_test.rb"
45
+ t.libs = %w(lib test)
46
+ t.pattern = 'lib/flipper/shared/test/**_test.rb'
47
47
  end
48
48
 
49
- task :default => [:spec, :test, :shared_test]
49
+ task default: [:spec, :test, :shared_test]
@@ -11,10 +11,11 @@ I plan on supporting the adapters in the flipper repo. Other adapters are welcom
11
11
  * [ActiveRecord adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_record) - Rails 3, 4, and 5.
12
12
  * [Sequel adapter](https://github.com/jnunemaker/flipper/blob/master/docs/sequel)
13
13
  * [Cassanity adapter](https://github.com/jnunemaker/flipper-cassanity)
14
+ * [read-only adapter](https://github.com/jnunemaker/flipper/blob/master/docs/read-only)
15
+ * [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http)
14
16
 
15
17
  ## Community Supported
16
18
 
17
- * [Active Record 4 adapter](https://github.com/bgentry/flipper-activerecord)
18
19
  * [Active Record 3 adapter](https://github.com/blueboxjesse/flipper-activerecord)
19
20
  * [Consul adapter](https://github.com/gdavison/flipper-consul)
20
21
 
@@ -7,9 +7,12 @@ new contributor could start working on code with a minumum efforts.
7
7
  ## Steps:
8
8
 
9
9
  1. Install Docker Compose https://docs.docker.com/compose/install
10
- 2. Install gems `docker-compose run --rm app bundle install`
11
- 3. Run specs `docker-compose run --rm app bundle exec rspec`
12
- 4. Optional: log in to container an using a bash for running specs
10
+ 1. Build the app container `docker-compose build`
11
+ 1. Install gems `docker-compose run --rm app bundle install`
12
+ 1. Run specs `docker-compose run --rm app bundle exec rspec`
13
+ 1. Run tests `docker-compose run --rm app bundle exec rake test`
14
+ 1. Clear and check files with Rubocop `docker-compose run --rm app bundle exec rubocop -D`
15
+ 1. Optional: log in to container an using a bash for running specs
13
16
  ```sh
14
17
  docker-compose run --rm app bash
15
18
  bundle exec rspec
@@ -24,8 +24,8 @@ end
24
24
 
25
25
  flipper = Flipper.new(adapter)
26
26
 
27
- flipper[:stats].enable flipper.group(:admins) # turn on for admins
28
- flipper[:stats].disable flipper.group(:admins) # turn off for admins
27
+ flipper[:stats].enable flipper.group(:admins) # turn on the stats feature for admins
28
+ flipper[:stats].disable flipper.group(:admins) # turn off the stats feature for admins
29
29
 
30
30
  person = Person.find(params[:id])
31
31
  flipper[:stats].enabled? person # check if enabled, returns true if person.admin? is true
@@ -37,7 +37,29 @@ flipper[:stats].enable_group :admins
37
37
  flipper[:stats].disable_group :admins
38
38
  ```
39
39
 
40
- There is no requirement that the thing yielded to the block be a user model or whatever. It can be anything you want, therefore it is a good idea to check that the thing passed into the group block actually responds to what you are trying.
40
+ Here's a quick explanation of the above code block:
41
+
42
+ ```
43
+ Flipper.register(:admins) do |actor|
44
+ actor.respond_to?(:admin?) && actor.admin?
45
+ end
46
+ ```
47
+ - The above first registers a group called `admins` which essentially saves a [Proc](http://www.eriktrautman.com/posts/ruby-explained-blocks-procs-and-lambdas-aka-closures) to be called later.
48
+
49
+ ```
50
+ flipper[:stats].enable flipper.group(:admins)
51
+ ```
52
+
53
+ - The above enables the stats feature to any object that returns true from the :admins proc.
54
+
55
+ ```
56
+ person = Person.find(params[:id])
57
+ flipper[:stats].enabled? person # check if person is enabled, returns true if person.admin? is true
58
+ ```
59
+
60
+ When the `person` object is passed to the `enabled?` method, it is then passed into the proc. If the proc returns true, the entire statement returns true and so `flipper[:stats].enabled? person` returns true. Whatever logic follows this conditional check is then executed.
61
+
62
+ There is no requirement that the thing yielded to the block be a user model or whatever. It can be anything you want, therefore it is a good idea to check that the thing passed into the group block actually responds to what you are trying to do in the `register` proc.
41
63
 
42
64
  ## 3. Individual Actor
43
65
 
@@ -12,8 +12,10 @@ You can use the middleware from a Rails initializer like so:
12
12
  # create flipper dsl instance, see above Usage for more details
13
13
  flipper = Flipper.new(...)
14
14
 
15
+ require 'flipper/middleware/setup_env'
15
16
  require 'flipper/middleware/memoizer'
16
- config.middleware.use Flipper::Middleware::Memoizer, flipper
17
+ config.middleware.use Flipper::Middleware::SetupEnv, flipper
18
+ config.middleware.use Flipper::Middleware::Memoizer
17
19
  ```
18
20
 
19
21
  If you set your flipper instance up in an initializer, you can pass a block to the middleware and it will lazily load the instance the first time the middleware is invoked.
@@ -27,9 +29,12 @@ module MyRailsApp
27
29
  end
28
30
 
29
31
  # config/application.rb
30
- config.middleware.use Flipper::Middleware::Memoizer, lambda {
32
+ require 'flipper/middleware/setup_env'
33
+ require 'flipper/middleware/memoizer'
34
+ config.middleware.use Flipper::Middleware::SetupEnv, lambda {
31
35
  MyRailsApp.flipper
32
36
  }
37
+ config.middleware.use Flipper::Middleware::Memoizer
33
38
  ```
34
39
 
35
40
  **Note**: Be sure that the middleware is high enough up in your stack that all feature checks are wrapped.
@@ -40,12 +45,12 @@ The Memoizer middleware also supports a few options. Use either `preload` or `pr
40
45
 
41
46
  * **`:preload`** - An `Array` of feature names (`Symbol`) to preload for every request. Useful if you have features that are used on every endpoint. `preload` uses `Adapter#get_multi` to attempt to load the features in one network call instead of N+1 network calls.
42
47
  ```ruby
43
- config.middleware.use Flipper::Middleware::Memoizer, flipper,
48
+ config.middleware.use Flipper::Middleware::Memoizer,
44
49
  preload: [:stats, :search, :some_feature]
45
50
  ```
46
- * **`:preload_all`** - A Boolean value (default: false) of whether or not all features should be preloaded. Using this results in a `preload` call with the result of `Adapter#features`. Any subsequent feature checks will be memoized and perform no network calls. I wouldn't recommend using this unless you have few features (< 30?) and nearly all of them are used on every request.
51
+ * **`:preload_all`** - A Boolean value (default: false) of whether or not all features should be preloaded. Using this results in a `preload` call with the result of `Adapter#features`. Any subsequent feature checks will be memoized and perform no network calls. I wouldn't recommend using this unless you have few features (< 30?) and nearly all of them are used on every request.
47
52
  ```ruby
48
- config.middleware.use Flipper::Middleware::Memoizer, flipper,
53
+ config.middleware.use Flipper::Middleware::Memoizer,
49
54
  preload_all: true
50
55
  ```
51
56
 
@@ -67,3 +72,20 @@ memory_adapter = Flipper::Adapters::Memory.new
67
72
  adapter = Flipper::Adapters::Dalli.new(memory_adapter, dalli_client, 600)
68
73
  flipper = Flipper.new(adapter)
69
74
  ```
75
+ ### RedisCache
76
+
77
+ Applications using [Redis](https://redis.io/) via the [redis-rb](https://github.com/redis/redis-rb) client can take advantage of the RedisCache adapter.
78
+
79
+ Initialize `RedisCache` with a flipper [adapter](https://github.com/jnunemaker/flipper/blob/master/docs/Adapters.md), a Redis client instance, and an optional TTL in seconds. TTL defaults to 3600 seconds.
80
+
81
+ Example using the RedisCache adapter with the Memory adapter and a TTL of 4800 seconds:
82
+
83
+ ```ruby
84
+ require 'flipper/adapters/memory'
85
+ require 'flipper/adapters/redis_cache'
86
+
87
+ redis = Redis.new(url: ENV['REDIS_URL'])
88
+ memory_adapter = Flipper::Adapters::Memory.new
89
+ adapter = Flipper::Adapters::RedisCache.new(memory_adapter, redis, 4800)
90
+ flipper = Flipper.new(adapter)
91
+ ```