flipper-redis 0.20.4 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38ed937a4141ea4dd894c5b12894a117d5117309106993ae73f541bbabf4ca52
4
- data.tar.gz: 79c9e9e33ff30120149967724ab170417cba12431cbae1dc46d243e4f2a4043c
3
+ metadata.gz: cb99d58e35c7f9ef6e7009d590b10567f892e12219d7e9932efd1fbf8738ca93
4
+ data.tar.gz: 29e58a9005b46a3c5369b627c4e202900c6f26fa3a21a037ce4bad5402027281
5
5
  SHA512:
6
- metadata.gz: 12e3459fc127df7292e9288dd4a63cf7a8c6332dcefc2f0bdfd80e145b1966dd1cdbb95913616f998a602b26e7e8b1c71f59052fdccccdca68ab66ce00a683c5
7
- data.tar.gz: c7215cefbff7c825dca2a15d2e10b49c021aad72ff4b4d51ac8131b32173b42aad70f4f2a10da724431121bf19ce71dd10b6e912e6525c0c09a27aca7dc99901
6
+ metadata.gz: 993919ce04acf986020d41383393f15312366f903eefc8db7331dfbe3b3223d6c15fab41b3755ac7e480bee71bf4dc257ab1425984d5203098a03b621e18c22e
7
+ data.tar.gz: eca5fc0aa2ffccd136dd5972c4e6bae7d43a28e27d5696a419e0fb3e94b6b5ac0227a1491b85f7c30e9600144033b5c4272da80c1d50330a6d35a26fce39643f
data/docs/redis/README.md CHANGED
@@ -18,12 +18,18 @@ Or install it yourself with:
18
18
 
19
19
  ## Usage
20
20
 
21
+ In most cases, all you need to do is require the adapter. It will connect to the Redis instance specified in the `REDIS_URL` or `FLIPPER_REDIS_URL` environment vairable, or localhost by default.
22
+
21
23
  ```ruby
22
24
  require 'flipper/adapters/redis'
23
- client = Redis.new
24
- adapter = Flipper::Adapters::Redis.new(client)
25
- flipper = Flipper.new(adapter)
26
- # profit...
25
+ ```
26
+
27
+ **If you need to customize the adapter**, you can add this to an initializer:
28
+
29
+ ```ruby
30
+ Flipper.configure do |config|
31
+ config.adapter { Flipper::Adapters::Redis.new(Redis.new) }
32
+ end
27
33
  ```
28
34
 
29
35
  ## Internals
@@ -1,30 +1,19 @@
1
- require 'pathname'
1
+ require 'bundler/setup'
2
2
  require 'logger'
3
3
 
4
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
5
- lib_path = root_path.join('lib')
6
- $:.unshift(lib_path)
7
-
8
4
  require 'flipper/adapters/redis'
9
- options = {}
10
- if ENV['REDIS_URL']
11
- options[:url] = ENV['REDIS_URL']
12
- end
13
- client = Redis.new(options)
14
- adapter = Flipper::Adapters::Redis.new(client)
15
- flipper = Flipper.new(adapter)
16
5
 
17
- flipper[:stats].enable
6
+ Flipper[:stats].enable
18
7
 
19
- if flipper[:stats].enabled?
8
+ if Flipper[:stats].enabled?
20
9
  puts "Enabled!"
21
10
  else
22
11
  puts "Disabled!"
23
12
  end
24
13
 
25
- flipper[:stats].disable
14
+ Flipper[:stats].disable
26
15
 
27
- if flipper[:stats].enabled?
16
+ if Flipper[:stats].enabled?
28
17
  puts "Enabled!"
29
18
  else
30
19
  puts "Disabled!"
@@ -1,20 +1,9 @@
1
+ require 'bundler/setup'
1
2
  require 'pp'
2
- require 'pathname'
3
3
  require 'logger'
4
-
5
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
6
- lib_path = root_path.join('lib')
7
- $:.unshift(lib_path)
8
-
9
4
  require 'flipper/adapters/redis'
10
5
 
11
- options = {}
12
- if ENV['REDIS_URL']
13
- options[:url] = ENV['REDIS_URL']
14
- end
15
- client = Redis.new(options)
16
- adapter = Flipper::Adapters::Redis.new(client)
17
- flipper = Flipper.new(adapter)
6
+ client = Redis.new
18
7
 
19
8
  # Register a few groups.
20
9
  Flipper.register(:admins) { |thing| thing.admin? }
@@ -23,16 +12,16 @@ Flipper.register(:early_access) { |thing| thing.early_access? }
23
12
  # Create a user class that has flipper_id instance method.
24
13
  User = Struct.new(:flipper_id)
25
14
 
26
- flipper[:stats].enable
27
- flipper[:stats].enable_group :admins
28
- flipper[:stats].enable_group :early_access
29
- flipper[:stats].enable_actor User.new('25')
30
- flipper[:stats].enable_actor User.new('90')
31
- flipper[:stats].enable_actor User.new('180')
32
- flipper[:stats].enable_percentage_of_time 15
33
- flipper[:stats].enable_percentage_of_actors 45
15
+ Flipper[:stats].enable
16
+ Flipper[:stats].enable_group :admins
17
+ Flipper[:stats].enable_group :early_access
18
+ Flipper[:stats].enable_actor User.new('25')
19
+ Flipper[:stats].enable_actor User.new('90')
20
+ Flipper[:stats].enable_actor User.new('180')
21
+ Flipper[:stats].enable_percentage_of_time 15
22
+ Flipper[:stats].enable_percentage_of_actors 45
34
23
 
35
- flipper[:search].enable
24
+ Flipper[:search].enable
36
25
 
37
26
  print 'all keys: '
38
27
  pp client.keys
@@ -64,7 +53,7 @@ pp client.hgetall('search')
64
53
  puts
65
54
 
66
55
  puts 'flipper get of feature'
67
- pp adapter.get(flipper[:stats])
56
+ pp Flipper.adapter.get(Flipper[:stats])
68
57
  # flipper get of feature
69
58
  # {:boolean=>"true",
70
59
  # :groups=>#<Set: {"admins", "early_access"}>,
@@ -1,18 +1,7 @@
1
- require 'pp'
2
- require 'pathname'
3
- require 'logger'
4
- begin
5
- require 'redis-namespace'
6
- rescue LoadError
7
- puts 'you must have redis-namespace gem installed'
8
- exit 1
9
- end
10
-
11
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
12
- lib_path = root_path.join('lib')
13
- $:.unshift(lib_path)
14
-
1
+ require 'bundler/setup'
2
+ require 'redis-namespace'
15
3
  require 'flipper/adapters/redis'
4
+
16
5
  options = {url: 'redis://127.0.0.1:6379'}
17
6
  if ENV['REDIS_URL']
18
7
  options[:url] = ENV['REDIS_URL']
@@ -178,3 +178,10 @@ module Flipper
178
178
  end
179
179
  end
180
180
  end
181
+
182
+ Flipper.configure do |config|
183
+ config.adapter do
184
+ client = Redis.new(url: ENV["FLIPPER_REDIS_URL"] || ENV["REDIS_URL"])
185
+ Flipper::Adapters::Redis.new(client)
186
+ end
187
+ end
@@ -148,7 +148,7 @@ module Flipper
148
148
  return [] if keys.empty?
149
149
 
150
150
  cache_keys = keys.map { |key| key_for(key) }
151
- @cache.mget(cache_keys).map do |value|
151
+ @cache.mget(*cache_keys).map do |value|
152
152
  value ? Marshal.load(value) : nil
153
153
  end
154
154
  end
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.20.4'.freeze
2
+ VERSION = '0.21.0'.freeze
3
3
  end
@@ -19,7 +19,11 @@ RSpec.describe Flipper::Adapters::RedisCache do
19
19
  subject { adapter }
20
20
 
21
21
  before do
22
- client.flushdb
22
+ begin
23
+ client.flushdb
24
+ rescue Redis::CannotConnectError
25
+ ENV['CI'] ? raise : skip('Redis not available')
26
+ end
23
27
  end
24
28
 
25
29
  it_should_behave_like 'a flipper adapter'
@@ -14,8 +14,21 @@ RSpec.describe Flipper::Adapters::Redis do
14
14
  subject { described_class.new(client) }
15
15
 
16
16
  before do
17
- client.flushdb
17
+ begin
18
+ client.flushdb
19
+ rescue Redis::CannotConnectError
20
+ ENV['CI'] ? raise : skip('Redis not available')
21
+ end
18
22
  end
19
23
 
20
24
  it_should_behave_like 'a flipper adapter'
25
+
26
+ it 'configures itself on load' do
27
+ Flipper.configuration = nil
28
+ Flipper.instance = nil
29
+
30
+ load 'flipper/adapters/redis.rb'
31
+
32
+ expect(Flipper.adapter.adapter).to be_a(Flipper::Adapters::Redis)
33
+ end
21
34
  end
@@ -9,6 +9,8 @@ class RedisCacheTest < MiniTest::Test
9
9
  @cache = Redis.new(url: url).tap(&:flushdb)
10
10
  memory_adapter = Flipper::Adapters::Memory.new
11
11
  @adapter = Flipper::Adapters::RedisCache.new(memory_adapter, @cache)
12
+ rescue Redis::CannotConnectError
13
+ ENV['CI'] ? raise : skip('Reids not available')
12
14
  end
13
15
 
14
16
  def teardown
@@ -8,5 +8,7 @@ class RedisTest < MiniTest::Test
8
8
  url = ENV.fetch('REDIS_URL', 'redis://localhost:6379')
9
9
  client = Redis.new(url: url).tap(&:flushdb)
10
10
  @adapter = Flipper::Adapters::Redis.new(client)
11
+ rescue Redis::CannotConnectError
12
+ ENV['CI'] ? raise : skip('Redis not available')
11
13
  end
12
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.4
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-06 00:00:00.000000000 Z
11
+ date: 2021-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: flipper
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.20.4
19
+ version: 0.21.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.20.4
26
+ version: 0.21.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: redis
29
29
  requirement: !ruby/object:Gem::Requirement