rcurtain 0.0.2 → 0.0.3
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 +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +33 -0
- data/README.md +58 -0
- data/lib/rcurtain/curtain.rb +37 -0
- data/lib/rcurtain/feature.rb +13 -0
- data/rcurtain.gemspec +19 -0
- data/spec/lib/curtain_spec.rb +65 -0
- data/spec/spec_helper.rb +13 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3c5aae4847c4ef5864c98f8e18c07f69a686513
|
4
|
+
data.tar.gz: ba76810da71297453711dd3c01ca9c162d950e56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8ed380aa872dfc64ce3c30a5d560edf64f792bebd9e1070a759bde0ce4082ab0ebc52d187924298f24a85178cdb76c182f170aec424f5792b5d69f1167d95e
|
7
|
+
data.tar.gz: 904aa233851ae90259dd0acebc59a5f1776b172d1a9c49e8dfdf8ce339daf3d5e7b24a90fae8f88b32ba35be962a98fa269f80efbf46dd26bfbf817dbbac06cd
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rcurtain (0.0.3)
|
5
|
+
hiredis
|
6
|
+
redis (~> 3.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
hiredis (0.6.1)
|
13
|
+
redis (3.3.0)
|
14
|
+
rspec (3.4.0)
|
15
|
+
rspec-core (~> 3.4.0)
|
16
|
+
rspec-expectations (~> 3.4.0)
|
17
|
+
rspec-mocks (~> 3.4.0)
|
18
|
+
rspec-core (3.4.4)
|
19
|
+
rspec-support (~> 3.4.0)
|
20
|
+
rspec-expectations (3.4.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.4.0)
|
23
|
+
rspec-mocks (3.4.1)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.4.0)
|
26
|
+
rspec-support (3.4.1)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
rcurtain!
|
33
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# RCurtain
|
2
|
+
|
3
|
+
Easy way to control your features using [redis](http://redis.io/).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rcurtain'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rcurtain
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
* Rcurtain uses redis to control features, which can be checked by a **percentage** or a **set of users**.
|
24
|
+
```
|
25
|
+
feature:[name-of-feature]:percentage
|
26
|
+
```
|
27
|
+
```
|
28
|
+
feature:[name-of-feature]:users
|
29
|
+
```
|
30
|
+
|
31
|
+
* To use Rcurtain, create a new object Rcurtain using your redis URL. (password@ip:port/database)
|
32
|
+
```ruby
|
33
|
+
rcurtain = Rcurtain.new("redis://:p4ssw0rd@10.0.1.1:6380/15")
|
34
|
+
```
|
35
|
+
|
36
|
+
* Consult if a feature is opened using the method "opened?", passing the name of the feature you want to check.
|
37
|
+
```ruby
|
38
|
+
rcurtain.opened? "feature"
|
39
|
+
```
|
40
|
+
|
41
|
+
* You can also pass a set of users to be checked.
|
42
|
+
```ruby
|
43
|
+
rcurtain.opened? ("feature", ['user-1','user-2'])
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/moip/rcurtain. 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.
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/moip/rcurtain/fork )
|
51
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
52
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
53
|
+
4. Push to the branch (git push origin my-new-feature)
|
54
|
+
5. Create a new Pull Request
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rcurtain
|
2
|
+
class Curtain
|
3
|
+
|
4
|
+
attr_reader :redis
|
5
|
+
|
6
|
+
def initialize (url)
|
7
|
+
@redis = Redis.new(:url => url)
|
8
|
+
end
|
9
|
+
|
10
|
+
def opened? (feature, users = [])
|
11
|
+
feat = get_feature(feature)
|
12
|
+
|
13
|
+
return (compare_percentage?(feat.percentage)) || (users.any? { |user| feat.users.include?(user)}) unless users.empty?
|
14
|
+
|
15
|
+
compare_percentage?(feat.percentage)
|
16
|
+
rescue Redis::CannotConnectError
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def get_feature (name)
|
22
|
+
percentage = redis.get("feature:#{name}:percentage")
|
23
|
+
percentage ||= 0
|
24
|
+
|
25
|
+
users = redis.smembers("feature:#{name}:users")
|
26
|
+
users ||= []
|
27
|
+
|
28
|
+
return Feature.new(name, percentage, users)
|
29
|
+
end
|
30
|
+
|
31
|
+
def compare_percentage? (percentage)
|
32
|
+
rnd = Random.new
|
33
|
+
rnd.rand(1..100) <= percentage.to_f
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/rcurtain.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'rcurtain'
|
3
|
+
s.version = '0.0.3'
|
4
|
+
s.date = '2016-05-26'
|
5
|
+
s.summary = "RCurtain"
|
6
|
+
s.description = "Open the curtain and see if your feature is enabled"
|
7
|
+
s.authors = ["Danillo Souza", "Gabriel Queiroz"]
|
8
|
+
s.email = ["danillo.souza@moip.com.br", "gabriel.queiroz@moip.com.br"]
|
9
|
+
s.homepage =
|
10
|
+
'http://github.com/moip/curtain'
|
11
|
+
s.license = 'MIT'
|
12
|
+
|
13
|
+
s.files = Dir['**/*'].keep_if { |file| File.file?(file) }
|
14
|
+
s.require_paths = ['lib']
|
15
|
+
|
16
|
+
s.add_runtime_dependency "hiredis"
|
17
|
+
s.add_runtime_dependency "redis", "~>3.2"
|
18
|
+
s.add_development_dependency "rspec"
|
19
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rcurtain do
|
4
|
+
|
5
|
+
subject(:rcurtain) { Rcurtain.new("redis://:p4ssw0rd@10.0.1.1:6380/15") }
|
6
|
+
|
7
|
+
context "is opened" do
|
8
|
+
|
9
|
+
context "when 100%" do
|
10
|
+
before do
|
11
|
+
allow_any_instance_of(Redis).to receive(:get).and_return(100)
|
12
|
+
allow_any_instance_of(Redis).to receive(:smembers).and_return(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
it { expect(rcurtain.opened? "feature").to be true }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when user exists" do
|
19
|
+
before do
|
20
|
+
allow_any_instance_of(Redis).to receive(:get).and_return(0)
|
21
|
+
allow_any_instance_of(Redis).to receive(:smembers).and_return(['MPA-123'])
|
22
|
+
end
|
23
|
+
|
24
|
+
it { expect(rcurtain.opened?("feature", ['MPA-123'])).to be true }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "is closed" do
|
29
|
+
context "when 0%" do
|
30
|
+
before do
|
31
|
+
allow_any_instance_of(Redis).to receive(:get).and_return(0)
|
32
|
+
allow_any_instance_of(Redis).to receive(:smembers).and_return(nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
it { expect(rcurtain.opened? "feature").to be false }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when user does not exists" do
|
39
|
+
before do
|
40
|
+
allow_any_instance_of(Redis).to receive(:get).and_return(0)
|
41
|
+
allow_any_instance_of(Redis).to receive(:smembers).and_return(["MPA-321"])
|
42
|
+
end
|
43
|
+
|
44
|
+
it { expect(rcurtain.opened?("feature", ['MPA-123'])).to be false }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when nothing was found on redis" do
|
48
|
+
before do
|
49
|
+
allow_any_instance_of(Redis).to receive(:get).and_return(nil)
|
50
|
+
allow_any_instance_of(Redis).to receive(:smembers).and_return(nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
it { expect(rcurtain.opened? "feature_not_found").to be false }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when failed connection" do
|
57
|
+
before do
|
58
|
+
allow_any_instance_of(Redis).to receive(:get).and_raise(Redis::CannotConnectError)
|
59
|
+
allow_any_instance_of(Redis).to receive(:smembers).and_raise(Redis::CannotConnectError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it { expect(rcurtain.opened? "feature").to be false }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
require 'rspec'
|
8
|
+
|
9
|
+
require "rcurtain"
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.raise_errors_for_deprecations!
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcurtain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danillo Souza
|
@@ -61,7 +61,15 @@ executables: []
|
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- README.md
|
64
67
|
- lib/rcurtain.rb
|
68
|
+
- lib/rcurtain/curtain.rb
|
69
|
+
- lib/rcurtain/feature.rb
|
70
|
+
- rcurtain.gemspec
|
71
|
+
- spec/lib/curtain_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
65
73
|
homepage: http://github.com/moip/curtain
|
66
74
|
licenses:
|
67
75
|
- MIT
|
@@ -82,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
90
|
version: '0'
|
83
91
|
requirements: []
|
84
92
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
93
|
+
rubygems_version: 2.4.3
|
86
94
|
signing_key:
|
87
95
|
specification_version: 4
|
88
96
|
summary: RCurtain
|