this_feature 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +34 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +81 -0
- data/LICENSE +21 -0
- data/README.md +69 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/this_feature.rb +38 -0
- data/lib/this_feature/adapters.rb +7 -0
- data/lib/this_feature/adapters/base.rb +36 -0
- data/lib/this_feature/adapters/flipper.rb +52 -0
- data/lib/this_feature/adapters/memory.rb +62 -0
- data/lib/this_feature/configuration.rb +26 -0
- data/lib/this_feature/errors.rb +23 -0
- data/lib/this_feature/flag.rb +32 -0
- data/lib/this_feature/version.rb +3 -0
- data/this_feature-adapters-flipper.gemspec +23 -0
- data/this_feature.gemspec +34 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b061ce7c8ed9133983dfc5435b15e70159f92226ecbdd2e96f3796e8e1bc6962
|
4
|
+
data.tar.gz: 3edd88333694e493d2e3c93bca6d1266a5d17ac9539771e7f434ad2e6d062eb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6ece19b22abae62d53094df235f29236a55970a3dd43f6b36818d8c5666181c7cf82326fd5b84c276095e484d39144e91bc186f8f88cb89efd2b0f4008fddd0
|
7
|
+
data.tar.gz: 1e2fd96239fb9c9f203475a95ed0c92ded460d35093ca97d69766ab72da8ed880868d135533cb034de867a1b2e85b04c5339eb1bf76ae357ec8a08df03143884
|
@@ -0,0 +1,34 @@
|
|
1
|
+
on: [push]
|
2
|
+
|
3
|
+
name: Test
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
run:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- name: Checkout
|
11
|
+
uses: actions/checkout@master
|
12
|
+
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: actions/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: '2.7.x'
|
17
|
+
bundler-cache: true
|
18
|
+
|
19
|
+
- name: Cache bundled gems
|
20
|
+
uses: actions/cache@v2
|
21
|
+
with:
|
22
|
+
path: vendor/bundle
|
23
|
+
key: ${{ runner.os }}-gems-${{ hashFiles('Gemfile.lock') }}
|
24
|
+
restore-keys: |
|
25
|
+
${{ runner.os }}-gems-
|
26
|
+
|
27
|
+
- name: Install Ruby gems
|
28
|
+
run: |
|
29
|
+
bundle config path vendor/bundle
|
30
|
+
bundle install
|
31
|
+
|
32
|
+
- name: Run Rspec
|
33
|
+
run: |
|
34
|
+
bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
10
|
+
and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
26
|
+
overall community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
31
|
+
advances of any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email
|
35
|
+
address, without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
shane.becker@hover.to.
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
86
|
+
of actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
93
|
+
permanent ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
113
|
+
the community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.0, available at
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
123
|
+
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
125
|
+
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
128
|
+
https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
this_feature (0.3.0)
|
5
|
+
this_feature-adapters-flipper (0.3.0)
|
6
|
+
flipper (~> 0.16)
|
7
|
+
flipper-active_record (~> 0.16)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (6.0.3.2)
|
13
|
+
activesupport (= 6.0.3.2)
|
14
|
+
activerecord (6.0.3.2)
|
15
|
+
activemodel (= 6.0.3.2)
|
16
|
+
activesupport (= 6.0.3.2)
|
17
|
+
activesupport (6.0.3.2)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 0.7, < 2)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
23
|
+
byebug (11.1.2)
|
24
|
+
coderay (1.1.2)
|
25
|
+
concurrent-ruby (1.1.6)
|
26
|
+
database_cleaner (1.8.4)
|
27
|
+
database_cleaner-active_record (1.8.0)
|
28
|
+
activerecord
|
29
|
+
database_cleaner (~> 1.8.0)
|
30
|
+
diff-lcs (1.3)
|
31
|
+
flipper (0.18.0)
|
32
|
+
flipper-active_record (0.18.0)
|
33
|
+
activerecord (>= 5.0, < 7)
|
34
|
+
flipper (~> 0.18.0)
|
35
|
+
gem-release (2.1.1)
|
36
|
+
i18n (1.8.5)
|
37
|
+
concurrent-ruby (~> 1.0)
|
38
|
+
method_source (1.0.0)
|
39
|
+
minitest (5.14.1)
|
40
|
+
pry (0.13.1)
|
41
|
+
coderay (~> 1.1)
|
42
|
+
method_source (~> 1.0)
|
43
|
+
pry-byebug (3.9.0)
|
44
|
+
byebug (~> 11.0)
|
45
|
+
pry (~> 0.13.0)
|
46
|
+
rake (13.0.1)
|
47
|
+
rspec (3.9.0)
|
48
|
+
rspec-core (~> 3.9.0)
|
49
|
+
rspec-expectations (~> 3.9.0)
|
50
|
+
rspec-mocks (~> 3.9.0)
|
51
|
+
rspec-core (3.9.1)
|
52
|
+
rspec-support (~> 3.9.1)
|
53
|
+
rspec-expectations (3.9.1)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.9.0)
|
56
|
+
rspec-mocks (3.9.1)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.9.0)
|
59
|
+
rspec-support (3.9.2)
|
60
|
+
sqlite3 (1.4.2)
|
61
|
+
thread_safe (0.3.6)
|
62
|
+
tzinfo (1.2.7)
|
63
|
+
thread_safe (~> 0.1)
|
64
|
+
zeitwerk (2.4.0)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
bundler (~> 2.0)
|
71
|
+
database_cleaner-active_record
|
72
|
+
gem-release
|
73
|
+
pry-byebug
|
74
|
+
rake (~> 13.0)
|
75
|
+
rspec (~> 3.0)
|
76
|
+
sqlite3
|
77
|
+
this_feature!
|
78
|
+
this_feature-adapters-flipper!
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 HOVER, Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# ThisFeature
|
2
|
+
|
3
|
+
The purpose of ThisFeature is to have one way to use feature flags
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'this_feature'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
gem install feature
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Currently
|
28
|
+
|
29
|
+
Currently, the only available adapter is `Flipper`.
|
30
|
+
We will update this document when more are added.
|
31
|
+
|
32
|
+
To set it up, put this in an initializer file:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
ThisFeature.set_adapters([ThisFeature::Adapters::FlipperAdapter])
|
36
|
+
```
|
37
|
+
|
38
|
+
This `set_adapters` will internally call the `.setup` method on the `FlipperAdapter`, which performs the Flipper initialization.
|
39
|
+
|
40
|
+
Then you can call `ThisFeature.enabled?("flag name")`.
|
41
|
+
|
42
|
+
It will iterate through the adapters until one of them returns `true`/`false`.
|
43
|
+
|
44
|
+
A context (`User` or `Org`) can be passed in the arguments to `enabled?` as well. `ThisFeature.enabled?(:flag_name, Current.user)`
|
45
|
+
|
46
|
+
### Planned
|
47
|
+
|
48
|
+
Create an initializer file in your Rails app:
|
49
|
+
|
50
|
+
`/config/initializers/this_feature.rb`
|
51
|
+
|
52
|
+
And set your list of adapters, _ordered by priority_. For example:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
ThisFeature.adapters = [SplitIO Flipper]
|
56
|
+
```
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
The tests are a good reflection of the current development state.
|
61
|
+
You can run the tests with these commands in your Terminal:
|
62
|
+
|
63
|
+
```
|
64
|
+
bundle install && bundle exec rspec
|
65
|
+
```
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
ThisFeature is released under the [MIT License](https://choosealicense.com/licenses/mit).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "this_feature"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/this_feature.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'this_feature/version'
|
2
|
+
require 'this_feature/adapters'
|
3
|
+
require 'this_feature/errors'
|
4
|
+
require 'this_feature/configuration'
|
5
|
+
require 'this_feature/flag'
|
6
|
+
|
7
|
+
class ThisFeature
|
8
|
+
def self.flag(flag_name, context: nil, data: {})
|
9
|
+
adapter = adapter_for(flag_name, context: nil, data: {})
|
10
|
+
|
11
|
+
Flag.new(flag_name, adapter: adapter, context: context, data: data)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.adapter_for(flag_name, context: nil, data: {})
|
15
|
+
matching_adapter = adapters.find do |adapter|
|
16
|
+
adapter.present?(flag_name, context: context, data: data)
|
17
|
+
end
|
18
|
+
|
19
|
+
matching_adapter || configuration.default_adapter
|
20
|
+
end
|
21
|
+
|
22
|
+
# Configuration
|
23
|
+
|
24
|
+
def self.configuration
|
25
|
+
@configuration ||= Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
|
31
|
+
configuration.init
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.adapters
|
35
|
+
configuration.adapters
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class ThisFeature
|
2
|
+
module Adapters
|
3
|
+
class Base
|
4
|
+
|
5
|
+
def self.setup
|
6
|
+
raise UnimplementedError.new(self, __method__)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.present?(flag_name)
|
10
|
+
raise UnimplementedError.new(self, __method__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.on?(flag_name, context: nil, data: {})
|
14
|
+
raise UnimplementedError.new(self, __method__)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.off?(flag_name, context: nil, data: {})
|
18
|
+
raise UnimplementedError.new(self, __method__)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.on!(flag_name, context: nil, data: {})
|
22
|
+
raise UnimplementedError.new(self, __method__)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.off!(flag_name, context: nil, data: {})
|
26
|
+
raise UnimplementedError.new(self, __method__)
|
27
|
+
end
|
28
|
+
|
29
|
+
# OPTIONAL method
|
30
|
+
# check to see if a control is being used
|
31
|
+
def self.control?(flag_name, context: nil, data: {})
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "flipper"
|
2
|
+
require "flipper/adapters/active_record"
|
3
|
+
|
4
|
+
class ThisFeature
|
5
|
+
module Adapters
|
6
|
+
class Flipper < Base
|
7
|
+
|
8
|
+
def self.setup(flipper = nil)
|
9
|
+
return @flipper = flipper unless flipper.nil?
|
10
|
+
|
11
|
+
@flipper = ::Flipper
|
12
|
+
|
13
|
+
::Flipper.configure do |config|
|
14
|
+
config.default do
|
15
|
+
adapter = ::Flipper::Adapters::ActiveRecord.new
|
16
|
+
::Flipper.new(adapter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.present?(flag_name)
|
22
|
+
flipper[flag_name].exist?
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.on?(flag_name, context: nil, data: {})
|
26
|
+
return unless present?(flag_name)
|
27
|
+
|
28
|
+
flipper[flag_name].enabled?(*[context].compact)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.off?(flag_name, context: nil, data: {})
|
32
|
+
on_result = on?(flag_name, context: context)
|
33
|
+
|
34
|
+
return if on_result.nil?
|
35
|
+
|
36
|
+
!on_result
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.on!(flag_name, context: nil, data: {})
|
40
|
+
flipper[flag_name].enable(*[context].compact)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.off!(flag_name, context: nil, data: {})
|
44
|
+
flipper[flag_name].disable(*[context].compact)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.flipper
|
48
|
+
@flipper
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class ThisFeature
|
2
|
+
module Adapters
|
3
|
+
class Memory < Base
|
4
|
+
|
5
|
+
def self.setup(context_id_method: :id)
|
6
|
+
@context_id_method = context_id_method
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.clear
|
10
|
+
storage.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.present?(flag_name)
|
14
|
+
!storage[flag_name].nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.on?(flag_name, context: nil, data: {})
|
18
|
+
# binding.pry
|
19
|
+
return unless present?(flag_name)
|
20
|
+
|
21
|
+
flag_data = storage[flag_name]
|
22
|
+
|
23
|
+
return true if flag_data[:global]
|
24
|
+
return false if context.nil?
|
25
|
+
|
26
|
+
flag_data[:contexts] ||= {}
|
27
|
+
|
28
|
+
!!flag_data[:contexts][context.send(@context_id_method)]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.off?(flag_name, context: nil, data: {})
|
32
|
+
on_result = on?(flag_name, context: context)
|
33
|
+
|
34
|
+
return if on_result.nil?
|
35
|
+
|
36
|
+
!on_result
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.on!(flag_name, context: nil, data: {})
|
40
|
+
storage[flag_name] ||= {}
|
41
|
+
|
42
|
+
return storage[flag_name][:global] = true if context.nil?
|
43
|
+
|
44
|
+
storage[flag_name][:contexts] ||= {}
|
45
|
+
storage[flag_name][:contexts][context.send(@context_id_method)] = true
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.off!(flag_name, context: nil, data: {})
|
49
|
+
storage[flag_name] ||= {}
|
50
|
+
|
51
|
+
return storage[flag_name][:global] = false if context.nil?
|
52
|
+
|
53
|
+
storage[flag_name][:contexts] ||= {}
|
54
|
+
storage[flag_name][:contexts][context.send(@context_id_method)] = false
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.storage
|
58
|
+
@storage ||= {}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
class ThisFeature
|
3
|
+
class Configuration
|
4
|
+
attr_writer :adapters, :default_adapter
|
5
|
+
|
6
|
+
def init
|
7
|
+
validate_adapters!
|
8
|
+
|
9
|
+
adapters.each(&:setup)
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate_adapters!
|
13
|
+
adapters.each do |adapter|
|
14
|
+
raise BadAdapterError.new(adapter) unless adapter < Adapters::Base
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def adapters
|
19
|
+
@adapters ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_adapter
|
23
|
+
@default_adapter ||= adapters.first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ThisFeature
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class UnimplementedError < Error
|
6
|
+
def initialize(klass, fn_name)
|
7
|
+
super("class #{klass.name} doesnt implement method .#{fn_name}")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class BadAdapterError < Error
|
12
|
+
def initialize(adapter)
|
13
|
+
super("adapter #{adapter.name} doesn't inherit from ThisFeature::Adapters::Base")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NoWriteAdapter < Error
|
18
|
+
def initialize
|
19
|
+
super("Use the `ThisFeature.write_adapter=` setter before calling #enable or #disable")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ThisFeature
|
2
|
+
class Flag
|
3
|
+
attr_reader :flag_name, :context, :data, :adapter
|
4
|
+
|
5
|
+
def initialize(flag_name, adapter:, context: nil, data: {})
|
6
|
+
@flag_name = flag_name
|
7
|
+
@adapter = adapter
|
8
|
+
@context = context
|
9
|
+
@data = data
|
10
|
+
end
|
11
|
+
|
12
|
+
def on?
|
13
|
+
adapter.on?(flag_name, context: context, data: data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def off?
|
17
|
+
adapter.off?(flag_name, context: context, data: data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def control?
|
21
|
+
adapter.control?(flag_name, context: context, data: data)
|
22
|
+
end
|
23
|
+
|
24
|
+
def on!
|
25
|
+
adapter.on!(flag_name, context: context, data: data)
|
26
|
+
end
|
27
|
+
|
28
|
+
def off!
|
29
|
+
adapter.off!(flag_name, context: context, data: data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
require 'this_feature/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'this_feature-adapters-flipper'
|
9
|
+
s.version = ThisFeature::VERSION
|
10
|
+
s.authors = ['Max Pleaner']
|
11
|
+
s.email = ['maxpleaner@gmail.com']
|
12
|
+
s.homepage = 'http://hover.to'
|
13
|
+
s.licenses = ['MIT']
|
14
|
+
s.summary = '[summary]'
|
15
|
+
s.description = '[description]'
|
16
|
+
|
17
|
+
s.files = Dir.glob('{bin/*,lib/**/*,[A-Z]*}')
|
18
|
+
s.platform = Gem::Platform::RUBY
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
|
21
|
+
s.add_runtime_dependency "flipper", "~> 0.16"
|
22
|
+
s.add_runtime_dependency "flipper-active_record", "~> 0.16"
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "this_feature/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "this_feature"
|
7
|
+
spec.version = ThisFeature::VERSION
|
8
|
+
spec.authors = ["Max Pleaner"]
|
9
|
+
spec.email = ["max.pleaner@hover.to"]
|
10
|
+
|
11
|
+
spec.summary = %q{Feature flag control}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/hoverinc/this_feature"
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "pry-byebug"
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "sqlite3"
|
32
|
+
spec.add_development_dependency "database_cleaner-active_record"
|
33
|
+
spec.add_development_dependency "gem-release"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: this_feature
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max Pleaner
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '13.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '13.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: database_cleaner-active_record
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gem-release
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Feature flag control
|
112
|
+
email:
|
113
|
+
- max.pleaner@hover.to
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".github/workflows/test.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- lib/this_feature.rb
|
131
|
+
- lib/this_feature/adapters.rb
|
132
|
+
- lib/this_feature/adapters/base.rb
|
133
|
+
- lib/this_feature/adapters/flipper.rb
|
134
|
+
- lib/this_feature/adapters/memory.rb
|
135
|
+
- lib/this_feature/configuration.rb
|
136
|
+
- lib/this_feature/errors.rb
|
137
|
+
- lib/this_feature/flag.rb
|
138
|
+
- lib/this_feature/version.rb
|
139
|
+
- this_feature-adapters-flipper.gemspec
|
140
|
+
- this_feature.gemspec
|
141
|
+
homepage: https://github.com/hoverinc/this_feature
|
142
|
+
licenses: []
|
143
|
+
metadata:
|
144
|
+
homepage_uri: https://github.com/hoverinc/this_feature
|
145
|
+
source_code_uri: https://github.com/hoverinc/this_feature
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubygems_version: 3.1.2
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: Feature flag control
|
165
|
+
test_files: []
|