flipper-redis 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ log
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'rake'
5
+
6
+ group(:guard) do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'growl'
11
+ end
12
+
13
+ group(:test) do
14
+ gem 'rspec'
15
+ gem 'redis'
16
+ end
17
+
@@ -0,0 +1,18 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'bundler' do
5
+ watch('Gemfile')
6
+ watch(/^.+\.gemspec/)
7
+ end
8
+
9
+ rspec_options = {
10
+ :all_after_pass => false,
11
+ :all_on_start => false,
12
+ }
13
+
14
+ guard 'rspec', rspec_options do
15
+ watch(%r{^spec/.+_spec\.rb$}) { "spec" }
16
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
17
+ watch('spec/helper.rb') { "spec" }
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Nunemaker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Flipper Redis
2
+
3
+ A redis adapter for [Flipper](https://github.com/jnunemaker/flipper), the feature flipping gems.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'flipper-redis'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself with:
16
+
17
+ $ gem install flipper-redis
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'flipper/adapters/redis'
23
+ client = Redis.new
24
+ adapter = Flipper::Adapters::Redis.new(client)
25
+ flipper = Flipper.new(adapter)
26
+ # profit...
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/flipper/adapters/redis/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["John Nunemaker"]
6
+ gem.email = ["nunemaker@gmail.com"]
7
+ gem.description = %q{Redis adapter for Flipper}
8
+ gem.summary = %q{Redis adapter for Flipper}
9
+ gem.homepage = "http://jnunemaker.github.com/flipper-redis"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "flipper-redis"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Flipper::Adapters::Redis::VERSION
17
+ gem.add_dependency 'flipper', '~> 0.1.0'
18
+ end
@@ -0,0 +1 @@
1
+ require 'flipper/adapters/redis'
@@ -0,0 +1,36 @@
1
+ require 'set'
2
+ require 'redis'
3
+
4
+ module Flipper
5
+ module Adapters
6
+ class Redis
7
+ def initialize(client)
8
+ @client = client
9
+ end
10
+
11
+ def read(key)
12
+ @client.get key
13
+ end
14
+
15
+ def write(key, value)
16
+ @client.set key, value
17
+ end
18
+
19
+ def delete(key)
20
+ @client.del key
21
+ end
22
+
23
+ def set_add(key, value)
24
+ @client.sadd(key, value)
25
+ end
26
+
27
+ def set_delete(key, value)
28
+ @client.srem(key, value)
29
+ end
30
+
31
+ def set_members(key)
32
+ @client.smembers(key).map { |member| member.to_i }.to_set
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ module Flipper
2
+ module Adapters
3
+ class Redis
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+ require 'flipper/adapters/redis'
3
+ require 'flipper/spec/shared_adapter_specs'
4
+
5
+ describe Flipper::Adapters::Redis do
6
+ let(:client) { Redis.new }
7
+
8
+ subject { Flipper::Adapters::Redis.new(client) }
9
+
10
+ before do
11
+ client.flushdb
12
+ end
13
+
14
+ def read_key(key)
15
+ client.get key
16
+ rescue RuntimeError => e
17
+ if e.message =~ /wrong kind of value/
18
+ client.smembers(key).map { |member| member.to_i }.to_set
19
+ else
20
+ raise
21
+ end
22
+ end
23
+
24
+ def write_key(key, value)
25
+ case value
26
+ when Array, Set
27
+ value.each do |member|
28
+ client.sadd key, member
29
+ end
30
+ else
31
+ client.set key, value
32
+ end
33
+ end
34
+
35
+ it_should_behave_like 'a flipper adapter'
36
+ end
@@ -0,0 +1,25 @@
1
+ $:.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require 'pathname'
4
+ require 'logger'
5
+
6
+ root_path = Pathname(__FILE__).dirname.join('..').expand_path
7
+ lib_path = root_path.join('lib')
8
+ log_path = root_path.join('log')
9
+ log_path.mkpath
10
+
11
+ require 'rubygems'
12
+ require 'bundler'
13
+
14
+ Bundler.require(:default, :test)
15
+
16
+ require 'flipper-redis'
17
+
18
+ Logger.new(log_path.join('test.log'))
19
+
20
+ RSpec.configure do |config|
21
+ config.filter_run :focused => true
22
+ config.alias_example_to :fit, :focused => true
23
+ config.alias_example_to :xit, :pending => true
24
+ config.run_all_when_everything_filtered = true
25
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flipper-redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Nunemaker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: flipper
16
+ requirement: &70155053349960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70155053349960
25
+ description: Redis adapter for Flipper
26
+ email:
27
+ - nunemaker@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Guardfile
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - flipper-redis.gemspec
39
+ - lib/flipper-redis.rb
40
+ - lib/flipper/adapters/redis.rb
41
+ - lib/flipper/adapters/redis/version.rb
42
+ - spec/flipper/redis_spec.rb
43
+ - spec/helper.rb
44
+ homepage: http://jnunemaker.github.com/flipper-redis
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ segments:
57
+ - 0
58
+ hash: 4066252487200743028
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ segments:
66
+ - 0
67
+ hash: 4066252487200743028
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 1.8.10
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Redis adapter for Flipper
74
+ test_files:
75
+ - spec/flipper/redis_spec.rb
76
+ - spec/helper.rb