feature_toggles 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/lib/feature_toggles.rb +12 -0
- data/lib/feature_toggles/mechatronic.rb +59 -0
- data/lib/feature_toggles/proxy.rb +26 -0
- data/lib/feature_toggles/version.rb +5 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b6aff154b3d0208aa37c53a90c3068e2a69fa393ba9e2e3b4a946e17f7479f2
|
4
|
+
data.tar.gz: d2aedea7c963de5cabcec3650b576eb20db4401ae3166978ab0cc0b76e998ebd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33972a4e5055b04dc3b6507d44b76fa6ed4ed81b594d086c6c0dfba579cf2fe09dbe0d06ccce9aad54390c33640087e61334edb22591cd81424f6b7903a6eb31
|
7
|
+
data.tar.gz: 7e50201fd0c9b9d9ac10babf891bd76bf5337303f2b46a7ad9026d38095ce71a5bdc9b0444efdf4158bbb9344f51ce26f406e0aac75e9695d9dffe03550ea9e6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 bibendi
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/feature_toggles.svg)](https://badge.fury.io/rb/feature_toggles)
|
2
|
+
[![Build Status](https://travis-ci.org/bibendi/feature_toggles.svg?branch=master)](https://travis-ci.org/bibendi/feature_toggles)
|
3
|
+
|
4
|
+
# FeatureToggles
|
5
|
+
|
6
|
+
This gem provides a mechanism for pending features that take longer than a single release cycle. The basic idea is to have a configuration file that defines a bunch of toggles for various features you have pending. The running application then uses these toggles in order to decide whether or not to show the new feature.
|
7
|
+
|
8
|
+
<a href="https://evilmartians.com/?utm_source=activerecord-postgres_enum">
|
9
|
+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'feature_toggles'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install feature_toggles
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
features = FeatureToggles.build do
|
31
|
+
# define env var prefix to enable features
|
32
|
+
# globally by passing MY_PREFIX_BAR=1
|
33
|
+
env "MY_PREFIX"
|
34
|
+
|
35
|
+
feature :bar do
|
36
|
+
user.can_bar?
|
37
|
+
end
|
38
|
+
|
39
|
+
feature :foo do |user: nil|
|
40
|
+
!user.nil? && user.can_foo?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
features.enabled?(:bar)
|
45
|
+
features.enabled?(:bar, user: user)
|
46
|
+
features.for(user: user).enabled?(:foo)
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bibendi/feature_toggles. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
62
|
+
|
63
|
+
## Code of Conduct
|
64
|
+
|
65
|
+
Everyone interacting in the FeatureToggles project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bibendi/feature_toggles/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "proxy"
|
4
|
+
|
5
|
+
module FeatureToggles
|
6
|
+
class Mechatronic
|
7
|
+
# Which env variables should be considered truthy
|
8
|
+
POSSIBLE_ENABLING_VALUES = %w(true on yes 1).freeze
|
9
|
+
|
10
|
+
def initialize(&block)
|
11
|
+
@features = {}
|
12
|
+
|
13
|
+
instance_eval(&block) if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def env(val)
|
17
|
+
@env_prefix = val
|
18
|
+
end
|
19
|
+
|
20
|
+
def feature(name, &block)
|
21
|
+
raise(ArgumentError, "Flag #{name} already exists") if @features.key?(name)
|
22
|
+
|
23
|
+
features[name] = block
|
24
|
+
end
|
25
|
+
|
26
|
+
def names
|
27
|
+
features.keys
|
28
|
+
end
|
29
|
+
|
30
|
+
def enabled?(feature, *args)
|
31
|
+
enabled_globally?(feature) || !!features.fetch(feature).call(*args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def for(*args)
|
35
|
+
Proxy.new(self, *args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_a(*args)
|
39
|
+
names.map do |feature|
|
40
|
+
{feature: feature, enabled: enabled?(feature, *args)}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_h(*args)
|
45
|
+
Hash[features.map do |feature, _|
|
46
|
+
[feature, enabled?(feature, *args)]
|
47
|
+
end]
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_reader :features, :env_prefix
|
53
|
+
|
54
|
+
def enabled_globally?(feature)
|
55
|
+
env_prefix &&
|
56
|
+
POSSIBLE_ENABLING_VALUES.include?(ENV["#{env_prefix}_#{feature.upcase}"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module FeatureToggles
|
4
|
+
class Proxy
|
5
|
+
def initialize(toggle, *args)
|
6
|
+
@toggle = toggle
|
7
|
+
@args = args
|
8
|
+
end
|
9
|
+
|
10
|
+
def enabled?(feature)
|
11
|
+
toggle.enabled?(feature, *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_a
|
15
|
+
toggle.to_a(*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
toggle.to_h(*args)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :toggle, :args
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: feature_toggles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Merkushin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-31 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: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.58'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.58'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- merkushin.m.s@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- lib/feature_toggles.rb
|
79
|
+
- lib/feature_toggles/mechatronic.rb
|
80
|
+
- lib/feature_toggles/proxy.rb
|
81
|
+
- lib/feature_toggles/version.rb
|
82
|
+
homepage: https://github.com/bibendi/feature_toggles
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
allowed_push_host: https://rubygems.org
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.7.6
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: This gem provides a mechanism for pending features.
|
107
|
+
test_files: []
|