rcurtain 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: b3c5aae4847c4ef5864c98f8e18c07f69a686513
4
- data.tar.gz: ba76810da71297453711dd3c01ca9c162d950e56
3
+ metadata.gz: ce878794b47c6035d21459a1c1af002fa6b940e1
4
+ data.tar.gz: 85c51fab7b638d6ddd973890f451b5230f5bef74
5
5
  SHA512:
6
- metadata.gz: bd8ed380aa872dfc64ce3c30a5d560edf64f792bebd9e1070a759bde0ce4082ab0ebc52d187924298f24a85178cdb76c182f170aec424f5792b5d69f1167d95e
7
- data.tar.gz: 904aa233851ae90259dd0acebc59a5f1776b172d1a9c49e8dfdf8ce339daf3d5e7b24a90fae8f88b32ba35be962a98fa269f80efbf46dd26bfbf817dbbac06cd
6
+ metadata.gz: 323fa3f0ccf54d90c751e23754e3b31037d90aaac48fd1af7a315fa4b1ced47be24272798b0b3cb7742f6d50662c797d050361d2ad97b8fa9759b2bb154cc912
7
+ data.tar.gz: 27ad99d24e74cd623c8c660e325b80b33e20d1d4231bd97f4108537409ecf2cfa3b7adb469e9e7146b94e624552889d70d7be9662b977270eff0c67380932185
data/Gemfile.lock CHANGED
@@ -31,3 +31,6 @@ PLATFORMS
31
31
  DEPENDENCIES
32
32
  rcurtain!
33
33
  rspec
34
+
35
+ BUNDLED WITH
36
+ 1.12.3
data/README.md CHANGED
@@ -28,20 +28,28 @@ feature:[name-of-feature]:percentage
28
28
  feature:[name-of-feature]:users
29
29
  ```
30
30
 
31
- * To use Rcurtain, create a new object Rcurtain using your redis URL. (password@ip:port/database)
31
+ * To use Rcurtain, first your need to initialize the configuration defining your **redis URL** (password@ip:port/database). Optionally, you can also configure the **default response** when the feature is not found, which by default is false.
32
32
  ```ruby
33
- rcurtain = Rcurtain.new("redis://:p4ssw0rd@10.0.1.1:6380/15")
34
- ```
33
+ Rcurtain.configure do |config|
34
+ config.url = 'redis://:p4ssw0rd@10.0.1.1:6380/15'
35
+ # config.default_response = true
36
+ end
37
+ ```
38
+
39
+ * Get the instance of Rcurtain.
40
+ ```ruby
41
+ rcurtain = Rcurtain.instance
42
+ ```
35
43
 
36
- * Consult if a feature is opened using the method "opened?", passing the name of the feature you want to check.
44
+ * Consult if the curtain is opened for a feature using the method "opened?", passing the name of the feature you want to check.
37
45
  ```ruby
38
- rcurtain.opened? "feature"
39
- ```
46
+ rcurtain.opened? 'feature'
47
+ ```
40
48
 
41
49
  * You can also pass a set of users to be checked.
42
50
  ```ruby
43
- rcurtain.opened? ("feature", ['user-1','user-2'])
44
- ```
51
+ rcurtain.opened?('feature', ['user-1','user-2'])
52
+ ```
45
53
 
46
54
  ## Contributing
47
55
 
data/lib/rcurtain.rb CHANGED
@@ -2,14 +2,24 @@ require "redis"
2
2
 
3
3
  require "rcurtain/feature"
4
4
  require "rcurtain/curtain"
5
+ require "rcurtain/configuration"
5
6
 
6
7
  module Rcurtain
7
8
 
8
9
  class << self
10
+ attr_writer :configuration
9
11
 
10
- def new(url)
11
- Curtain.new(url)
12
+ def instance
13
+ Curtain.instance
12
14
  end
15
+ end
16
+
17
+ def self.configuration
18
+ @configuration ||= Configuration.new
19
+ end
13
20
 
21
+ def self.configure
22
+ @configuration = Configuration.new
23
+ yield(configuration)
14
24
  end
15
25
  end
@@ -0,0 +1,10 @@
1
+ module Rcurtain
2
+ class Configuration
3
+
4
+ attr_accessor :url, :default_response
5
+
6
+ def initialize
7
+ @default_response = false
8
+ end
9
+ end
10
+ end
@@ -1,10 +1,13 @@
1
+ require "singleton"
2
+
1
3
  module Rcurtain
2
4
  class Curtain
5
+ include Singleton
3
6
 
4
7
  attr_reader :redis
5
8
 
6
- def initialize (url)
7
- @redis = Redis.new(:url => url)
9
+ def initialize
10
+ @redis = Redis.new(:url => Rcurtain.configuration.url)
8
11
  end
9
12
 
10
13
  def opened? (feature, users = [])
@@ -14,7 +17,7 @@ module Rcurtain
14
17
 
15
18
  compare_percentage?(feat.percentage)
16
19
  rescue Redis::CannotConnectError
17
- return false
20
+ return Rcurtain.configuration.default_response
18
21
  end
19
22
 
20
23
  private
data/rcurtain.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rcurtain'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.date = '2016-05-26'
5
5
  s.summary = "RCurtain"
6
6
  s.description = "Open the curtain and see if your feature is enabled"
7
7
  s.authors = ["Danillo Souza", "Gabriel Queiroz"]
8
8
  s.email = ["danillo.souza@moip.com.br", "gabriel.queiroz@moip.com.br"]
9
9
  s.homepage =
10
- 'http://github.com/moip/curtain'
10
+ 'http://github.com/moip/rcurtain'
11
11
  s.license = 'MIT'
12
12
 
13
13
  s.files = Dir['**/*'].keep_if { |file| File.file?(file) }
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rcurtain do
4
+
5
+ describe "#configure" do
6
+
7
+ context "configure url for redis" do
8
+ before do
9
+ Rcurtain.configure do |config|
10
+ config.url = 'redis://:p4ssw0rd@10.0.1.1:6380/15'
11
+ end
12
+ end
13
+
14
+ subject(:rcurtain) { Rcurtain.configuration }
15
+
16
+ it {expect(subject.url).to eq('redis://:p4ssw0rd@10.0.1.1:6380/15')}
17
+
18
+ end
19
+
20
+ context "configure default response" do
21
+ before do
22
+ Rcurtain.configure do |config|
23
+ config.default_response = true
24
+ end
25
+ end
26
+
27
+ subject(:rcurtain) { Rcurtain.configuration }
28
+
29
+ it {expect(subject.default_response).to eq true}
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -2,7 +2,13 @@ require "spec_helper"
2
2
 
3
3
  describe Rcurtain do
4
4
 
5
- subject(:rcurtain) { Rcurtain.new("redis://:p4ssw0rd@10.0.1.1:6380/15") }
5
+ before do
6
+ Rcurtain.configure do |config|
7
+ config.url = 'redis://:p4ssw0rd@10.0.1.1:6380/15'
8
+ end
9
+ end
10
+
11
+ subject(:rcurtain) { Rcurtain.instance }
6
12
 
7
13
  context "is opened" do
8
14
 
@@ -62,4 +68,5 @@ describe Rcurtain do
62
68
  it { expect(rcurtain.opened? "feature").to be false }
63
69
  end
64
70
  end
71
+
65
72
  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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danillo Souza
@@ -65,12 +65,14 @@ files:
65
65
  - Gemfile.lock
66
66
  - README.md
67
67
  - lib/rcurtain.rb
68
+ - lib/rcurtain/configuration.rb
68
69
  - lib/rcurtain/curtain.rb
69
70
  - lib/rcurtain/feature.rb
70
71
  - rcurtain.gemspec
72
+ - spec/lib/configuration_spec.rb
71
73
  - spec/lib/curtain_spec.rb
72
74
  - spec/spec_helper.rb
73
- homepage: http://github.com/moip/curtain
75
+ homepage: http://github.com/moip/rcurtain
74
76
  licenses:
75
77
  - MIT
76
78
  metadata: {}
@@ -90,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  version: '0'
91
93
  requirements: []
92
94
  rubyforge_project:
93
- rubygems_version: 2.4.3
95
+ rubygems_version: 2.5.1
94
96
  signing_key:
95
97
  specification_version: 4
96
98
  summary: RCurtain