flipper-moneta 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/docs/moneta/README.md +79 -0
- data/flipper-moneta.gemspec +24 -0
- data/lib/flipper/adapters/moneta.rb +104 -0
- data/lib/flipper/version.rb +3 -0
- data/spec/flipper/adapters/moneta_spec.rb +10 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 60ddcdab338dfec08b158bdce0edc0212ec555ea
|
4
|
+
data.tar.gz: e9292cb6ab46824f1223a7eee7ee62178c6a6f75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7cc144518020adca2a26a466a06561dd6fb32d210386600b625bb7a1efd0d472b9bce00c55f0aa8aff93b81777fa038e8efa443246e98cec6546433e2c54b2f
|
7
|
+
data.tar.gz: 6b52df892008bb4c8c1575d93d34d2e5bc2f23d9b0c3eec3549f010f8ee9a598993e09eac574b5dbd67e3d3f037f21224b4db581f346abbd4ab22d5111929872
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Flipper Moneta
|
2
|
+
|
3
|
+
A [Moneta](https://github.com/minad/moneta) adapter for [Flipper](https://github.com/jnunemaker/flipper).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'flipper-moneta'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself with:
|
16
|
+
|
17
|
+
$ gem install flipper-moneta
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'flipper/adapters/moneta'
|
23
|
+
moneta = Moneta.new(:Memory)
|
24
|
+
adapter = Flipper::Adapters::Moneta.new(moneta)
|
25
|
+
|
26
|
+
Flipper.configure do |config|
|
27
|
+
config.default do
|
28
|
+
Flipper.new(adapter)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Internals
|
34
|
+
|
35
|
+
Each feature is stored as a key namespaced by `flipper_features`.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'flipper/adapters/moneta'
|
39
|
+
moneta = Moneta.new(:Memory)
|
40
|
+
adapter = Flipper::Adapters::Moneta.new(moneta)
|
41
|
+
|
42
|
+
Flipper.configure do |config|
|
43
|
+
config.default do
|
44
|
+
Flipper.new(adapter)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Register a few groups.
|
49
|
+
Flipper.register(:admins) { |thing| thing.admin? }
|
50
|
+
Flipper.register(:early_access) { |thing| thing.early_access? }
|
51
|
+
|
52
|
+
# Create a user class that has flipper_id instance method.
|
53
|
+
User = Struct.new(:flipper_id)
|
54
|
+
|
55
|
+
Flipper[:stats].enable
|
56
|
+
Flipper[:stats].enable_group :admins
|
57
|
+
Flipper[:stats].enable_group :early_access
|
58
|
+
Flipper[:stats].enable_actor User.new('25')
|
59
|
+
Flipper[:stats].enable_actor User.new('90')
|
60
|
+
Flipper[:stats].enable_actor User.new('180')
|
61
|
+
Flipper[:stats].enable_percentage_of_time 15
|
62
|
+
Flipper[:stats].enable_percentage_of_actors 45
|
63
|
+
|
64
|
+
pp moneta["flipper_features/stats"]
|
65
|
+
|
66
|
+
{:boolean=>"true",
|
67
|
+
:groups=>#<Set: {"admins", "early_access"}>,
|
68
|
+
:actors=>#<Set: {"25", "90", "180"}>,
|
69
|
+
:percentage_of_actors=>"45",
|
70
|
+
:percentage_of_time=>"15"}
|
71
|
+
```
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
1. Fork it
|
76
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
77
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
78
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
79
|
+
5. Create new Pull Request
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/flipper/version', __FILE__)
|
3
|
+
|
4
|
+
flipper_moneta_files = lambda do |file|
|
5
|
+
file =~ /moneta/
|
6
|
+
end
|
7
|
+
|
8
|
+
Gem::Specification.new do |gem|
|
9
|
+
gem.authors = ['John Nunemaker']
|
10
|
+
gem.email = ['nunemaker@gmail.com']
|
11
|
+
gem.summary = 'Moneta adapter for Flipper'
|
12
|
+
gem.description = 'Moneta adapter for Flipper'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
gem.homepage = 'https://github.com/jnunemaker/flipper'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split("\n").select(&flipper_moneta_files) + ['lib/flipper/version.rb']
|
17
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n").select(&flipper_moneta_files)
|
18
|
+
gem.name = 'flipper-moneta'
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
gem.version = Flipper::VERSION
|
21
|
+
|
22
|
+
gem.add_dependency 'flipper', "~> #{Flipper::VERSION}"
|
23
|
+
gem.add_dependency 'moneta', '>= 0.7.0', '<= 1.0.0'
|
24
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'moneta'
|
2
|
+
|
3
|
+
module Flipper
|
4
|
+
module Adapters
|
5
|
+
class Moneta
|
6
|
+
include ::Flipper::Adapter
|
7
|
+
|
8
|
+
FEATURES_KEY = :flipper_features
|
9
|
+
|
10
|
+
# Public: The name of the adapter.
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
# Public
|
14
|
+
def initialize(moneta)
|
15
|
+
@moneta = moneta
|
16
|
+
@name = :moneta
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: The set of known features
|
20
|
+
def features
|
21
|
+
moneta[FEATURES_KEY] || Set.new
|
22
|
+
end
|
23
|
+
|
24
|
+
# Public: Adds a feature to the set of known features.
|
25
|
+
def add(feature)
|
26
|
+
moneta[FEATURES_KEY] = features << feature.key.to_s
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
# Public: Removes a feature from the set of known features and clears
|
31
|
+
# all the values for the feature.
|
32
|
+
def remove(feature)
|
33
|
+
moneta[FEATURES_KEY] = features.delete(feature.key.to_s)
|
34
|
+
moneta.delete(key(feature.key))
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Public: Clears all the gate values for a feature.
|
39
|
+
def clear(feature)
|
40
|
+
moneta[key(feature.key)] = default_config
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
# Public: Gets the values for all gates for a given feature.
|
45
|
+
#
|
46
|
+
# Returns a Hash of Flipper::Gate#key => value.
|
47
|
+
def get(feature)
|
48
|
+
default_config.merge(moneta[key(feature.key)].to_h)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Public: Enables a gate for a given thing.
|
52
|
+
#
|
53
|
+
# feature - The Flipper::Feature for the gate.
|
54
|
+
# gate - The Flipper::Gate to disable.
|
55
|
+
# thing - The Flipper::Type being enabled for the gate.
|
56
|
+
#
|
57
|
+
# Returns true.
|
58
|
+
def enable(feature, gate, thing)
|
59
|
+
case gate.data_type
|
60
|
+
when :boolean, :integer
|
61
|
+
result = get(feature)
|
62
|
+
result[gate.key] = thing.value.to_s
|
63
|
+
moneta[key(feature.key)] = result
|
64
|
+
when :set
|
65
|
+
result = get(feature)
|
66
|
+
result[gate.key] << thing.value.to_s
|
67
|
+
moneta[key(feature.key)] = result
|
68
|
+
end
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
# Public: Disables a gate for a given thing.
|
73
|
+
#
|
74
|
+
# feature - The Flipper::Feature for the gate.
|
75
|
+
# gate - The Flipper::Gate to disable.
|
76
|
+
# thing - The Flipper::Type being disabled for the gate.
|
77
|
+
#
|
78
|
+
# Returns true.
|
79
|
+
def disable(feature, gate, thing)
|
80
|
+
case gate.data_type
|
81
|
+
when :boolean
|
82
|
+
clear(feature)
|
83
|
+
when :integer
|
84
|
+
result = get(feature)
|
85
|
+
result[gate.key] = thing.value.to_s
|
86
|
+
moneta[key(feature.key)] = result
|
87
|
+
when :set
|
88
|
+
result = get(feature)
|
89
|
+
result[gate.key] = result[gate.key].delete(thing.value.to_s)
|
90
|
+
moneta[key(feature.key)] = result
|
91
|
+
end
|
92
|
+
true
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def key(feature_key)
|
98
|
+
"#{FEATURES_KEY}/#{feature_key}"
|
99
|
+
end
|
100
|
+
|
101
|
+
attr_reader :moneta
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'flipper/adapters/moneta'
|
3
|
+
require 'flipper/spec/shared_adapter_specs'
|
4
|
+
|
5
|
+
RSpec.describe Flipper::Adapters::Moneta do
|
6
|
+
let(:moneta) { Moneta.new(:Memory) }
|
7
|
+
subject { described_class.new(moneta) }
|
8
|
+
|
9
|
+
it_should_behave_like 'a flipper adapter'
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flipper-moneta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.16.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Nunemaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: flipper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.16.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.16.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: moneta
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.0
|
34
|
+
- - "<="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.0
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.7.0
|
44
|
+
- - "<="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.0
|
47
|
+
description: Moneta adapter for Flipper
|
48
|
+
email:
|
49
|
+
- nunemaker@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- docs/moneta/README.md
|
55
|
+
- flipper-moneta.gemspec
|
56
|
+
- lib/flipper/adapters/moneta.rb
|
57
|
+
- lib/flipper/version.rb
|
58
|
+
- spec/flipper/adapters/moneta_spec.rb
|
59
|
+
homepage: https://github.com/jnunemaker/flipper
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.5.4
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Moneta adapter for Flipper
|
83
|
+
test_files:
|
84
|
+
- spec/flipper/adapters/moneta_spec.rb
|