this_feature-adapters-flipper 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: 22af6aafd342c298c31378889d21f2f762b5ae5b96c36068a5297be4bb91cc3c
4
- data.tar.gz: 67bfd16d7027c4c9ff4fe302bc559e2f3fffc68c54ef8b5dc374d174487ab53d
3
+ metadata.gz: 3710e3b7ca63182b688e5d869aae0da012e0a7cc62cca117f5eb88e5886298fe
4
+ data.tar.gz: 0b4ececf219ab511b50853856d1e62f010419f1aacbc9b50a3bd00bc3f4d706f
5
5
  SHA512:
6
- metadata.gz: 40d04ebd41d2861ce29170706d6aff6d8da1455d190c592af2a133bf9fa0eaef778308a8eb5c75127d48e54aef79a6a1a2d35e31ca9662ee8e16a8f51dc3cee5
7
- data.tar.gz: b8896633916796b3a01dc395e8b34c16c0c0051009f5ef8d2d04c313b3d99875da0130f823603c1818792a08417293ff7d4a18d36c3640da3651e57c1e91978c
6
+ metadata.gz: 56a00ef7e2cd7dfbf95c71f89776145e22001aaf9a43bf04c4f7c22ade02920d14f6face379ee29e4d3ab92bea61854d096ff94591cc60d679ac12cbf9e290e6
7
+ data.tar.gz: a6250717cde602636be9bdbc5687a71e96633490781008561ee6def906d7b01d0a9d17cb4eff8b37f7a6002538085311889ad7a1d2e9e8c7cc169c045576bb82
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- this_feature (0.4.0)
5
- this_feature-adapters-flipper (0.4.0)
4
+ this_feature (0.5.3)
5
+ this_feature-adapters-flipper (0.5.3)
6
6
  flipper (~> 0.16)
7
7
  flipper-active_record (~> 0.16)
8
8
  this_feature
9
- this_feature-adapters-split_io (0.4.0)
9
+ this_feature-adapters-split_io (0.5.3)
10
10
  splitclient-rb
11
11
  this_feature
12
12
 
@@ -35,10 +35,10 @@ GEM
35
35
  diff-lcs (1.3)
36
36
  faraday (1.0.1)
37
37
  multipart-post (>= 1.2, < 3)
38
- flipper (0.18.0)
39
- flipper-active_record (0.18.0)
38
+ flipper (0.19.0)
39
+ flipper-active_record (0.19.0)
40
40
  activerecord (>= 5.0, < 7)
41
- flipper (~> 0.18.0)
41
+ flipper (~> 0.19.0)
42
42
  gem-release (2.1.1)
43
43
  hitimes (1.3.1)
44
44
  i18n (1.8.5)
@@ -58,7 +58,7 @@ GEM
58
58
  byebug (~> 11.0)
59
59
  pry (~> 0.13.0)
60
60
  rake (13.0.1)
61
- redis (4.2.1)
61
+ redis (4.2.2)
62
62
  rspec (3.9.0)
63
63
  rspec-core (~> 3.9.0)
64
64
  rspec-expectations (~> 3.9.0)
data/README.md CHANGED
@@ -1,65 +1,44 @@
1
1
  # ThisFeature
2
2
 
3
- The purpose of ThisFeature is to have one way to use feature flags
3
+ **A common interface to interact with many feature flag providers.**
4
4
 
5
- ## Installation
5
+ Can be used to more easily migrate among providers.
6
+
7
+ If your code uses ThisFeature,
8
+ then you can just swap out the adapter without having to do a bunch of find-and-replace.
6
9
 
7
- Add this line to your application's `Gemfile`:
10
+ ## Installation
8
11
 
9
12
  ```ruby
10
13
  gem 'this_feature'
11
14
  ```
12
15
 
13
- And then execute:
14
-
15
- ```sh
16
- bundle
17
- ```
18
-
19
- Or install it yourself as:
20
-
21
- ```sh
22
- gem install this_feature
23
- ```
24
-
25
16
  ## Configuration
26
17
 
27
18
  ```ruby
28
19
  # config/initializers/this_feature.rb
29
20
  require 'this_feature'
21
+ require 'this_feature/adapters/memory'
30
22
 
31
23
  ThisFeature.configure do |config|
32
- config.adapters = [ThisFeature::Adapters::Memory]
33
- config.default_adapter = config.adapters.first
24
+ adapter = ThisFeature::Adapters::Memory.new
25
+ config.adapters = [adapter]
26
+ config.default_adapter = adapter
34
27
  end
35
28
  ```
36
29
 
37
30
  **NOTE**: When searching for the presence of a flag, adapters are queried in order. The default adapter is the fallback adapter used when a flag isn't present in any of the adapters.
38
31
 
39
-
40
- ### With Flipper
41
-
42
- ```ruby
43
- # config/initializers/this_feature.rb
44
- require 'this_feature/adapters/flipper'
45
-
46
- ThisFeature.configure do |config|
47
- config.adapters = [ThisFeature::Adapters::Flipper]
48
- config.default_adapter = config.adapters.first
49
- end
50
- ```
51
-
52
-
53
-
54
32
  ## Usage
55
33
 
56
34
  ### Flags
35
+
57
36
  ```ruby
58
- ThisFeature.flag('flag_name').on? # check if flag is turned on
59
- ThisFeature.flag('flag_name').off? # check if flag is turned off
60
- ThisFeature.flag('flag_name').control? # see if the adapter is using the control
61
- ThisFeature.flag('flag_name').on! # turn on the flag
62
- ThisFeature.flag('flag_name').off! # turn off the flag
37
+ ThisFeature.flag('flag_name').on? # is the flag is turned on?
38
+ ThisFeature.flag('flag_name').off? # is the flag is turned off?
39
+ ThisFeature.flag('flag_name').control? # is the adapter is using the control?
40
+ ThisFeature.flag('flag_name').present? # is the flag set at all?
41
+ ThisFeature.default_adapter # access the default adapter directly if needed
63
42
  ```
64
43
 
65
44
  ### Context
@@ -78,8 +57,13 @@ In case context is not sufficient, you can also pass a data hash.
78
57
  ThisFeature.flag('flag_name', context: context, data: { org_id: 1 }).on?
79
58
  ```
80
59
 
81
- ## TODO: Write documentation for the adapters (creating adapters, using memory adapter, using flipper adapter)
60
+ ## Available Adapters
61
+
62
+ These adapters do behave slightly differently, so make sure to read the following docs:
82
63
 
64
+ - [Flipper adapter](./docs/flipper.md)
65
+ - [Split.io adapter](./docs/splitio.md)
66
+ - [Memory adapter](./docs/memory.md) - **designed for use in tests**
83
67
 
84
68
  ## Development
85
69
 
@@ -90,6 +74,11 @@ You can run the tests with these commands in your Terminal:
90
74
  bundle install && bundle exec rspec
91
75
  ```
92
76
 
77
+ To write a new adapter, check the [Guide](./docs/writing_an_adapter.md).
78
+
93
79
  ## License
94
80
 
95
81
  ThisFeature is released under the [MIT License](https://choosealicense.com/licenses/mit).
82
+
83
+
84
+
@@ -34,4 +34,8 @@ class ThisFeature
34
34
  def self.adapters
35
35
  configuration.adapters
36
36
  end
37
+
38
+ def self.test_adapter
39
+ configuration.test_adapter
40
+ end
37
41
  end
@@ -1,11 +1,6 @@
1
1
  class ThisFeature
2
2
  module Adapters
3
3
  class Base
4
-
5
- def setup
6
- raise UnimplementedError.new(self, __method__)
7
- end
8
-
9
4
  def present?(flag_name)
10
5
  raise UnimplementedError.new(self, __method__)
11
6
  end
@@ -19,17 +19,11 @@ class ThisFeature
19
19
  end
20
20
 
21
21
  def on?(flag_name, context: nil, data: {})
22
- return unless present?(flag_name)
23
-
24
22
  client[flag_name].enabled?(*[context].compact)
25
23
  end
26
24
 
27
25
  def off?(flag_name, context: nil, data: {})
28
- on_result = on?(flag_name, context: context)
29
-
30
- return if on_result.nil?
31
-
32
- !on_result
26
+ !on?(flag_name, context: context)
33
27
  end
34
28
 
35
29
  private
@@ -15,7 +15,7 @@ class ThisFeature
15
15
  end
16
16
 
17
17
  def on?(flag_name, context: nil, data: {})
18
- return unless present?(flag_name)
18
+ return false unless present?(flag_name)
19
19
 
20
20
  flag_data = storage[flag_name]
21
21
 
@@ -28,11 +28,7 @@ class ThisFeature
28
28
  end
29
29
 
30
30
  def off?(flag_name, context: nil, data: {})
31
- on_result = on?(flag_name, context: context)
32
-
33
- return if on_result.nil?
34
-
35
- !on_result
31
+ !on?(flag_name, context: context, data: data)
36
32
  end
37
33
 
38
34
  def on!(flag_name, context: nil, data: {})
@@ -17,7 +17,7 @@ class ThisFeature
17
17
  end
18
18
 
19
19
  def control?(flag_name, context: UNDEFINED_KEY, data: {})
20
- treatment(flag_name, context: context, data: data).eql?('control_treatment')
20
+ treatment(flag_name, context: context, data: data).include?('control')
21
21
  end
22
22
 
23
23
  def on?(flag_name, context: UNDEFINED_KEY, data: {})
@@ -1,13 +1,14 @@
1
-
2
1
  class ThisFeature
3
2
  class Configuration
4
- attr_writer :adapters, :default_adapter
3
+ attr_writer :adapters, :default_adapter, :test_adapter
5
4
 
6
5
  def init
7
6
  validate_adapters!
8
7
  end
9
8
 
10
9
  def validate_adapters!
10
+ raise(NoAdaptersError.new) unless adapters.any?
11
+
11
12
  adapters.each do |adapter|
12
13
  raise BadAdapterError.new(adapter) unless adapter.class < Adapters::Base
13
14
  end
@@ -20,5 +21,9 @@ class ThisFeature
20
21
  def default_adapter
21
22
  @default_adapter ||= adapters.first
22
23
  end
24
+
25
+ def test_adapter
26
+ @test_adapter ||= Adapters::Memory.new
27
+ end
23
28
  end
24
29
  end
@@ -14,9 +14,9 @@ class ThisFeature
14
14
  end
15
15
  end
16
16
 
17
- class NoWriteAdapter < Error
17
+ class NoAdaptersError < Error
18
18
  def initialize
19
- super("Use the `ThisFeature.write_adapter=` setter before calling #enable or #disable")
19
+ super("No adapters configured.")
20
20
  end
21
21
  end
22
22
 
@@ -1,3 +1,3 @@
1
1
  class ThisFeature
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.3"
3
3
  end
data/memory CHANGED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: this_feature-adapters-flipper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Pleaner
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-11 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: this_feature
@@ -85,7 +85,7 @@ homepage: http://hover.to
85
85
  licenses:
86
86
  - MIT
87
87
  metadata: {}
88
- post_install_message:
88
+ post_install_message:
89
89
  rdoc_options: []
90
90
  require_paths:
91
91
  - lib
@@ -100,8 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.1.2
104
- signing_key:
103
+ rubygems_version: 3.0.3
104
+ signing_key:
105
105
  specification_version: 4
106
106
  summary: "[summary]"
107
107
  test_files: []