this_feature 0.6.1 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03e205e9b9a6a53ff76d8c93b315eb7e8cd2f05a96a9e7f4ae9ac434371155e9
4
- data.tar.gz: 1e5e996c866d55076f205a47685e295e4b04f0373aa545d183c0192d640ac8a0
3
+ metadata.gz: 8812767db56e7467a7439bc73bd243e3829974f9ee8897b85e434a036d0cdff9
4
+ data.tar.gz: b27419213f0bb1954a7d9c221ce315ae2229f2bb27fee13ae92b8987371d7c24
5
5
  SHA512:
6
- metadata.gz: 4ea504d76f8f435166ba50bb4643065030e40ea44626ffd4222fe60a5f80588d3242fe89dc339b14cce7b8cc1657fef016c9c59e5decdc9879f3bf64f23581b5
7
- data.tar.gz: 523abe2a99278d2c559931e3b89ba0a946ca03f5e7a3fc92fd0e060555d0a0b25308d863f57904f4f4cc9ddb5fd93535e79bcee9164cff769b3d2ee61a6fcf0c
6
+ metadata.gz: cc7fe3136ed720c6eca4aed7ee10a02faf9e3eca3f39302137f7b375e408bf7be7b6259e5fa6ab7b631d9c929fa6c562c25e697cc2ff061a0d204c982dc45a73
7
+ data.tar.gz: 6b7e73cead9d55c2c116c9fda04a61c789b2ab8c368d53535958f38f6fe8a7e1191842119e1c469d6d4459a55c4ad722dfdf2e24b9fb64ec95bcbcf5bc1ca36b
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- this_feature (0.6.1)
5
- this_feature-adapters-flipper (0.6.1)
4
+ this_feature (0.7.0)
5
+ this_feature-adapters-flipper (0.7.0)
6
6
  flipper (~> 0.16)
7
7
  flipper-active_record (~> 0.16)
8
8
  this_feature
9
- this_feature-adapters-split_io (0.6.1)
9
+ this_feature-adapters-split_io (0.7.0)
10
10
  splitclient-rb
11
11
  this_feature
12
12
 
@@ -27,27 +27,39 @@ GEM
27
27
  byebug (11.1.2)
28
28
  coderay (1.1.2)
29
29
  concurrent-ruby (1.1.8)
30
- connection_pool (2.2.3)
30
+ connection_pool (2.2.5)
31
31
  database_cleaner (1.8.4)
32
32
  database_cleaner-active_record (1.8.0)
33
33
  activerecord
34
34
  database_cleaner (~> 1.8.0)
35
35
  diff-lcs (1.3)
36
- faraday (1.3.0)
36
+ faraday (1.5.0)
37
+ faraday-em_http (~> 1.0)
38
+ faraday-em_synchrony (~> 1.0)
39
+ faraday-excon (~> 1.1)
40
+ faraday-httpclient (~> 1.0.1)
37
41
  faraday-net_http (~> 1.0)
42
+ faraday-net_http_persistent (~> 1.1)
43
+ faraday-patron (~> 1.0)
38
44
  multipart-post (>= 1.2, < 3)
39
- ruby2_keywords
45
+ ruby2_keywords (>= 0.0.4)
46
+ faraday-em_http (1.0.0)
47
+ faraday-em_synchrony (1.0.0)
48
+ faraday-excon (1.1.0)
49
+ faraday-httpclient (1.0.1)
40
50
  faraday-net_http (1.0.1)
41
- flipper (0.20.3)
42
- flipper-active_record (0.20.3)
43
- activerecord (>= 5.0, < 7)
44
- flipper (~> 0.20.3)
51
+ faraday-net_http_persistent (1.1.0)
52
+ faraday-patron (1.0.0)
53
+ flipper (0.22.0)
54
+ flipper-active_record (0.22.0)
55
+ activerecord (>= 4.2, < 7)
56
+ flipper (~> 0.22.0)
45
57
  gem-release (2.2.1)
46
58
  hitimes (1.3.1)
47
59
  i18n (1.8.9)
48
60
  concurrent-ruby (~> 1.0)
49
61
  json (2.5.1)
50
- jwt (2.2.2)
62
+ jwt (2.2.3)
51
63
  lru_redux (1.1.0)
52
64
  method_source (1.0.0)
53
65
  minitest (5.14.4)
@@ -61,7 +73,7 @@ GEM
61
73
  byebug (~> 11.0)
62
74
  pry (~> 0.13.0)
63
75
  rake (13.0.1)
64
- redis (4.2.5)
76
+ redis (4.3.1)
65
77
  rspec (3.9.0)
66
78
  rspec-core (~> 3.9.0)
67
79
  rspec-expectations (~> 3.9.0)
data/README.md CHANGED
@@ -2,17 +2,27 @@
2
2
 
3
3
  **A common interface to interact with many feature flag providers.**
4
4
 
5
- Can be used to more easily migrate among providers.
5
+ ThisFeature can be used to more easily migrate from one feature flag service to another
6
6
 
7
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.
8
+ then you can just swap out the vendor adapter without needing to do a bunch of find-and-replace in your codebase
9
+ from one vendor's class/method signature to the another's.
9
10
 
10
11
  ## Installation
11
12
 
13
+ Add ThisFeature to your `Gemfile`:
14
+
12
15
  ```ruby
16
+ # Gemfile
13
17
  gem 'this_feature'
14
18
  ```
15
19
 
20
+ Then from your Rails app's root directory:
21
+
22
+ ```sh
23
+ bundle install
24
+ ```
25
+
16
26
  ## Configuration
17
27
 
18
28
  ```ruby
@@ -36,14 +46,13 @@ end
36
46
  ```ruby
37
47
  ThisFeature.flag('flag_name').on? # is the flag is turned on?
38
48
  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?
49
+ ThisFeature.flag('flag_name').control? # is the adapter using the control?
41
50
  ThisFeature.default_adapter # access the default adapter directly if needed
42
51
  ```
43
52
 
44
53
  ### Context
45
54
 
46
- You can also pass a context to the flag, many feature flagging systems support this.
55
+ You can also pass a `context` to the flag, many feature flagging systems support this.
47
56
 
48
57
  ```ruby
49
58
  ThisFeature.flag('flag_name', context: current_user).on?
@@ -51,12 +60,17 @@ ThisFeature.flag('flag_name', context: current_user).on?
51
60
 
52
61
  ### Data
53
62
 
54
- In case context is not sufficient, you can also pass a data hash.
63
+ In case `context` is not sufficient, you can also pass a `data` hash.
55
64
 
56
65
  ```ruby
57
66
  ThisFeature.flag('flag_name', context: context, data: { org_id: 1 }).on?
58
67
  ```
59
68
 
69
+ ### Avoid Pitfalls
70
+
71
+ 1. If your flag has context-specific rules (e.g. on for some orgs, off for others), make sure that the code does a context-specific check. `ThisFeature.flag("flag_name").on?` may return true, while `ThisFeature.flag("flag_name", context: Org.first).on?` would return false.
72
+ 2. Related to the previous bullet point, if you are checking whether a flag is "globally enabled" (and thus may be removed from the codebase), do not just use `ThisFeature.flag("flag_name").on?`, it won't tell you the whole story. Go to the vendor console and check whether there are context-specific rules enabled.
73
+
60
74
  ## Available Adapters
61
75
 
62
76
  These adapters do behave slightly differently, so make sure to read the following docs:
@@ -65,6 +79,16 @@ These adapters do behave slightly differently, so make sure to read the followin
65
79
  - [Split.io adapter](./docs/splitio.md)
66
80
  - [Memory adapter](./docs/memory.md) - **designed for use in tests**
67
81
 
82
+ ### Needed Adapters
83
+
84
+ We'd like to add more adapters for more vendors.
85
+ If you're using a different backend and write your own adapter,
86
+ please submit a pull request to upstream that adaptor into this repo.
87
+
88
+ - Launch Darkly
89
+ - YAML files
90
+ - ...
91
+
68
92
  ## Development
69
93
 
70
94
  The tests are a good reflection of the current development state.
@@ -19,11 +19,11 @@ class ThisFeature
19
19
 
20
20
  flag_data = storage[flag_name]
21
21
 
22
- return true if flag_data[:global]
23
- return false if context.nil?
22
+ context_registered = flag_data[:contexts]&.key?(context_key(context))
24
23
 
25
- flag_data[:contexts] ||= {}
24
+ return !!flag_data[:global] if !context || (context && !context_registered)
26
25
 
26
+ flag_data[:contexts] ||= {}
27
27
  !!flag_data[:contexts][context_key(context)]
28
28
  end
29
29
 
@@ -62,6 +62,7 @@ class ThisFeature
62
62
  attr_reader :context_key_method
63
63
 
64
64
  def context_key(context)
65
+ return nil unless context
65
66
  return context if context_key_method.nil?
66
67
 
67
68
  context.send(context_key_method)
@@ -1,3 +1,3 @@
1
1
  class ThisFeature
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: this_feature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Pleaner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2021-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  requirements: []
168
- rubygems_version: 3.1.2
168
+ rubygems_version: 3.0.3
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Feature flag control