Skip to content
Browse files

Note moved status

  • Loading branch information...
1 parent c24fda5 commit c0516b2dd9f4f0e116db8cd6542646166f9d64a8 @jnunemaker committed Apr 28, 2015
Showing with 4 additions and 592 deletions.
  1. +0 −18 .gitignore
  2. +0 −11 .travis.yml
  3. +0 −13 Gemfile
  4. +0 −18 Guardfile
  5. +0 −22 LICENSE
  6. +4 −117 README.md
  7. +0 −5 Rakefile
  8. +0 −27 examples/basic.rb
  9. +0 −71 examples/internals.rb
  10. +0 −20 flipper-redis.gemspec
  11. +0 −1 lib/flipper-redis.rb
  12. +0 −142 lib/flipper/adapters/redis.rb
  13. +0 −7 lib/flipper/adapters/redis/version.rb
  14. +0 −21 script/bootstrap
  15. +0 −42 script/release
  16. +0 −23 script/test
  17. +0 −23 spec/flipper/redis_spec.rb
  18. +0 −11 spec/helper.rb
View
18 .gitignore
@@ -1,18 +0,0 @@
-*.gem
-*.rbc
-.bundle
-.config
-.yardoc
-Gemfile.lock
-InstalledFiles
-_yardoc
-coverage
-doc/
-lib/bundler/man
-pkg
-rdoc
-spec/reports
-test/tmp
-test/version_tmp
-tmp
-log
View
11 .travis.yml
@@ -1,11 +0,0 @@
-language: ruby
-rvm:
- - 1.8.7
- - ree
- - 1.9.3
-notifications:
- email: false
-bundler_args: --without guard
-before_script: sudo service redis-server status
-services:
- - redis-server
View
13 Gemfile
@@ -1,13 +0,0 @@
-source 'https://rubygems.org'
-gemspec
-
-gem 'redis-namespace', :require => false
-gem 'rake'
-gem 'rspec'
-
-group(:guard) do
- gem 'guard'
- gem 'guard-rspec'
- gem 'guard-bundler'
- gem 'rb-fsevent'
-end
View
18 Guardfile
@@ -1,18 +0,0 @@
-# A sample Guardfile
-# More info at https://github.com/guard/guard#readme
-
-guard 'bundler' do
- watch('Gemfile')
- watch(/^.+\.gemspec/)
-end
-
-rspec_options = {
- :all_after_pass => false,
- :all_on_start => false,
-}
-
-guard 'rspec', rspec_options do
- watch(%r{^spec/.+_spec\.rb$}) { "spec" }
- watch(%r{^lib/(.+)\.rb$}) { "spec" }
- watch('spec/helper.rb') { "spec" }
-end
View
22 LICENSE
@@ -1,22 +0,0 @@
-Copyright (c) 2012 John Nunemaker
-
-MIT License
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
121 README.md
@@ -1,119 +1,6 @@
-# Flipper Redis
+# MOVED
-A [Redis](https://github.com/redis/redis-rb) adapter for [Flipper](https://github.com/jnunemaker/flipper).
+This repo has merged with the main flipper repo. The gem is still separate. You can read more over at the main flipper repo:
-## Installation
-
-Add this line to your application's Gemfile:
-
- gem 'flipper-redis'
-
-And then execute:
-
- $ bundle
-
-Or install it yourself with:
-
- $ gem install flipper-redis
-
-## Usage
-
-```ruby
-require 'flipper/adapters/redis'
-client = Redis.new
-adapter = Flipper::Adapters::Redis.new(client)
-flipper = Flipper.new(adapter)
-# profit...
-```
-
-## Internals
-
-Each feature is stored in a redis hash, which means getting a feature is single query.
-
-```ruby
-require 'flipper/adapters/redis'
-require 'redis/namespace'
-
-client = Redis.new
-namespaced_client = Redis::Namespace.new(:flipper, :redis => client)
-adapter = Flipper::Adapters::Redis.new(namespaced_client)
-flipper = Flipper.new(adapter)
-
-# Register a few groups.
-Flipper.register(:admins) { |thing| thing.admin? }
-Flipper.register(:early_access) { |thing| thing.early_access? }
-
-# Create a user class that has flipper_id instance method.
-User = Struct.new(:flipper_id)
-
-flipper[:stats].enable
-flipper[:stats].enable flipper.group(:admins)
-flipper[:stats].enable flipper.group(:early_access)
-flipper[:stats].enable User.new('25')
-flipper[:stats].enable User.new('90')
-flipper[:stats].enable User.new('180')
-flipper[:stats].enable flipper.random(15)
-flipper[:stats].enable flipper.actors(45)
-
-flipper[:search].enable
-
-print 'all keys: '
-pp namespaced_client.keys
-# all keys: ["stats", "flipper_features", "search"]
-
-print "known flipper features: "
-pp namespaced_client.smembers("flipper_features")
-# known flipper features: ["stats", "search"]
-
-puts 'stats keys'
-pp namespaced_client.hgetall('stats')
-# stats keys
-# {"boolean"=>"true",
-# "groups/admins"=>"1",
-# "actors/25"=>"1",
-# "percentage_of_random"=>"15",
-# "percentage_of_actors"=>"45",
-# "groups/early_access"=>"1",
-# "actors/90"=>"1",
-# "actors/180"=>"1"}
-
-puts 'search keys'
-pp namespaced_client.hgetall('search')
-# search keys
-# {"boolean"=>"true"}
-
-puts 'flipper get of feature'
-pp adapter.get(flipper[:stats])
-# flipper get of feature
-# {:boolean=>"true",
-# :groups=>#<Set: {"admins", "early_access"}>,
-# :actors=>#<Set: {"25", "90", "180"}>,
-# :percentage_of_actors=>"45",
-# :percentage_of_random=>"15"}
-```
-
-## `script/bootstrap`
-
-This script will get all the dependencies ready so you can start hacking.
-
-```
-# to learn more about script/bootstrap
-script/bootstrap help
-```
-
-## `script/test`
-
-For your convenience, there is a script to run the tests. It will also perform `script/bootstrap`, which bundles and all that jazz.
-
-```
-# to learn more about script test
-script/test help
-```
-
-## Contributing
-
-1. Fork it
-2. Create your feature branch (`git checkout -b my-new-feature`)
-3. Commit your changes (`git commit -am 'Added some feature'`)
-4. Push to the branch (`git push origin my-new-feature`)
-5. Create new Pull Request
+https://github.com/jnunemaker/flipper
+https://github.com/jnunemaker/flipper/blob/master/docs/redis/README.md
View
5 Rakefile
@@ -1,5 +0,0 @@
-#!/usr/bin/env rake
-require 'rspec/core/rake_task'
-RSpec::Core::RakeTask.new
-
-task :default => :spec
View
27 examples/basic.rb
@@ -1,27 +0,0 @@
-require 'pathname'
-require 'logger'
-
-root_path = Pathname(__FILE__).dirname.join('..').expand_path
-lib_path = root_path.join('lib')
-$:.unshift(lib_path)
-
-require 'flipper/adapters/redis'
-client = Redis.new
-adapter = Flipper::Adapters::Redis.new(client)
-flipper = Flipper.new(adapter)
-
-flipper[:stats].enable
-
-if flipper[:stats].enabled?
- puts "Enabled!"
-else
- puts "Disabled!"
-end
-
-flipper[:stats].disable
-
-if flipper[:stats].enabled?
- puts "Enabled!"
-else
- puts "Disabled!"
-end
View
71 examples/internals.rb
@@ -1,71 +0,0 @@
-require 'pp'
-require 'pathname'
-require 'logger'
-
-root_path = Pathname(__FILE__).dirname.join('..').expand_path
-lib_path = root_path.join('lib')
-$:.unshift(lib_path)
-
-require 'flipper/adapters/redis'
-require 'redis/namespace'
-
-client = Redis.new
-namespaced_client = Redis::Namespace.new(:flipper, :redis => client)
-adapter = Flipper::Adapters::Redis.new(namespaced_client)
-flipper = Flipper.new(adapter)
-
-# Register a few groups.
-Flipper.register(:admins) { |thing| thing.admin? }
-Flipper.register(:early_access) { |thing| thing.early_access? }
-
-# Create a user class that has flipper_id instance method.
-User = Struct.new(:flipper_id)
-
-flipper[:stats].enable
-flipper[:stats].enable flipper.group(:admins)
-flipper[:stats].enable flipper.group(:early_access)
-flipper[:stats].enable User.new('25')
-flipper[:stats].enable User.new('90')
-flipper[:stats].enable User.new('180')
-flipper[:stats].enable flipper.random(15)
-flipper[:stats].enable flipper.actors(45)
-
-flipper[:search].enable
-
-print 'all keys: '
-pp namespaced_client.keys
-# all keys: ["stats", "flipper_features", "search"]
-puts
-
-print "known flipper features: "
-pp namespaced_client.smembers("flipper_features")
-# known flipper features: ["stats", "search"]
-puts
-
-puts 'stats keys'
-pp namespaced_client.hgetall('stats')
-# stats keys
-# {"boolean"=>"true",
-# "groups/admins"=>"1",
-# "actors/25"=>"1",
-# "percentage_of_random"=>"15",
-# "percentage_of_actors"=>"45",
-# "groups/early_access"=>"1",
-# "actors/90"=>"1",
-# "actors/180"=>"1"}
-puts
-
-puts 'search keys'
-pp namespaced_client.hgetall('search')
-# search keys
-# {"boolean"=>"true"}
-puts
-
-puts 'flipper get of feature'
-pp adapter.get(flipper[:stats])
-# flipper get of feature
-# {:boolean=>"true",
-# :groups=>#<Set: {"admins", "early_access"}>,
-# :actors=>#<Set: {"25", "90", "180"}>,
-# :percentage_of_actors=>"45",
-# :percentage_of_random=>"15"}
View
20 flipper-redis.gemspec
@@ -1,20 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/flipper/adapters/redis/version', __FILE__)
-
-Gem::Specification.new do |gem|
- gem.name = "flipper-redis"
- gem.version = Flipper::Adapters::Redis::VERSION
- gem.authors = ["John Nunemaker"]
- gem.email = ["nunemaker@gmail.com"]
- gem.description = %q{Redis adapter for Flipper}
- gem.summary = %q{Redis adapter for Flipper}
- gem.homepage = "http://jnunemaker.github.com/flipper-redis"
- gem.require_paths = ["lib"]
-
- gem.files = `git ls-files`.split($/)
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
-
- gem.add_dependency 'flipper', '~> 0.7.0.beta1'
- gem.add_dependency 'redis', '>= 2.2', '< 4.0.0'
-end
View
1 lib/flipper-redis.rb
@@ -1 +0,0 @@
-require 'flipper/adapters/redis'
View
142 lib/flipper/adapters/redis.rb
@@ -1,142 +0,0 @@
-require 'set'
-require 'redis'
-require 'flipper'
-
-module Flipper
- module Adapters
- class Redis
- include Flipper::Adapter
-
- # Private: The key that stores the set of known features.
- FeaturesKey = :flipper_features
-
- # Public: The name of the adapter.
- attr_reader :name
-
- # Public: Initializes a Redis flipper adapter.
- #
- # client - The Redis client to use. Feel free to namespace it.
- def initialize(client)
- @client = client
- @name = :redis
- end
-
- # Public: The set of known features.
- def features
- @client.smembers(FeaturesKey).to_set
- end
-
- # Public: Adds a feature to the set of known features.
- def add(feature)
- @client.sadd FeaturesKey, feature.name
- true
- end
-
- # Public: Removes a feature from the set of known features.
- def remove(feature)
- @client.multi do
- @client.srem FeaturesKey, feature.name
- @client.del feature.key
- end
- true
- end
-
- # Public: Clears the gate values for a feature.
- def clear(feature)
- @client.del feature.key
- true
- end
-
- # Public: Gets the values for all gates for a given feature.
- #
- # Returns a Hash of Flipper::Gate#key => value.
- def get(feature)
- result = {}
- doc = doc_for(feature)
- fields = doc.keys
-
- feature.gates.each do |gate|
- result[gate.key] = case gate.data_type
- when :boolean, :integer
- doc[gate.key.to_s]
- when :set
- fields_to_gate_value fields, gate
- else
- unsupported_data_type gate.data_type
- end
- end
-
- result
- end
-
- # Public: Enables a gate for a given thing.
- #
- # feature - The Flipper::Feature for the gate.
- # gate - The Flipper::Gate to disable.
- # thing - The Flipper::Type being disabled for the gate.
- #
- # Returns true.
- def enable(feature, gate, thing)
- case gate.data_type
- when :boolean, :integer
- @client.hset feature.key, gate.key, thing.value.to_s
- when :set
- @client.hset feature.key, to_field(gate, thing), 1
- else
- unsupported_data_type gate.data_type
- end
-
- true
- end
-
- # Public: Disables a gate for a given thing.
- #
- # feature - The Flipper::Feature for the gate.
- # gate - The Flipper::Gate to disable.
- # thing - The Flipper::Type being disabled for the gate.
- #
- # Returns true.
- def disable(feature, gate, thing)
- case gate.data_type
- when :boolean
- @client.del feature.key
- when :integer
- @client.hset feature.key, gate.key, thing.value.to_s
- when :set
- @client.hdel feature.key, to_field(gate, thing)
- else
- unsupported_data_type gate.data_type
- end
-
- true
- end
-
- # Private: Gets a hash of fields => values for the given feature.
- #
- # Returns a Hash of fields => values.
- def doc_for(feature)
- @client.hgetall(feature.key)
- end
-
- # Private: Converts gate and thing to hash key.
- def to_field(gate, thing)
- "#{gate.key}/#{thing.value}"
- end
-
- # Private: Returns a set of values given an array of fields and a gate.
- #
- # Returns a Set of the values enabled for the gate.
- def fields_to_gate_value(fields, gate)
- regex = /^#{Regexp.escape(gate.key.to_s)}\//
- keys = fields.grep(regex)
- values = keys.map { |key| key.split('/', 2).last }
- values.to_set
- end
-
- # Private
- def unsupported_data_type(data_type)
- raise "#{data_type} is not supported by this adapter"
- end
- end
- end
-end
View
7 lib/flipper/adapters/redis/version.rb
@@ -1,7 +0,0 @@
-module Flipper
- module Adapters
- class Redis
- VERSION = "0.7.0.beta1"
- end
- end
-end
View
21 script/bootstrap
@@ -1,21 +0,0 @@
-#!/bin/sh
-#/ Usage: bootstrap [bundle options]
-#/
-#/ Bundle install the dependencies.
-#/
-#/ Examples:
-#/
-#/ bootstrap
-#/ bootstrap --local
-#/
-
-set -e
-cd $(dirname "$0")/..
-
-[ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
- grep '^#/' <"$0"| cut -c4-
- exit 0
-}
-
-rm -rf .bundle/{binstubs,config}
-bundle install --binstubs .bundle/binstubs --path .bundle --quiet "$@"
View
42 script/release
@@ -1,42 +0,0 @@
-#!/bin/sh
-#/ Usage: release
-#/
-#/ Tag the version in the repo and push the gem.
-#/
-
-set -e
-cd $(dirname "$0")/..
-
-[ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
- grep '^#/' <"$0"| cut -c4-
- exit 0
-}
-
-gem_name=flipper-redis
-
-# Build a new gem archive.
-rm -rf $gem_name-*.gem
-gem build -q $gem_name.gemspec
-
-# Make sure we're on the master branch.
-(git branch | grep -q '* master') || {
- echo "Only release from the master branch."
- exit 1
-}
-
-# Figure out what version we're releasing.
-tag=v`ls $gem_name-*.gem | sed "s/^$gem_name-\(.*\)\.gem$/\1/"`
-
-echo "Releasing $tag"
-
-# Make sure we haven't released this version before.
-git fetch -t origin
-
-(git tag -l | grep -q "$tag") && {
- echo "Whoops, there's already a '${tag}' tag."
- exit 1
-}
-
-# Tag it and bag it.
-gem push $gem_name-*.gem && git tag "$tag" &&
- git push origin master && git push origin "$tag"
View
23 script/test
@@ -1,23 +0,0 @@
-#!/bin/sh
-#/ Usage: test [individual test file]
-#/
-#/ Bootstrap and run all tests or an individual test.
-#/
-#/ Examples:
-#/
-#/ # run all tests
-#/ test
-#/
-#/ # run individual test
-#/ test test/controller_instrumentation_test.rb
-#/
-
-set -e
-cd $(dirname "$0")/..
-
-[ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
- grep '^#/' <"$0"| cut -c4-
- exit 0
-}
-
-script/bootstrap && bundle exec rake spec
View
23 spec/flipper/redis_spec.rb
@@ -1,23 +0,0 @@
-require 'helper'
-require 'flipper/adapters/redis'
-require 'flipper/spec/shared_adapter_specs'
-
-describe Flipper::Adapters::Redis do
- let(:client) {
- options = {}
-
- if ENV['BOXEN_REDIS_URL']
- options[:url] = ENV['BOXEN_REDIS_URL']
- end
-
- Redis.new(options)
- }
-
- subject { described_class.new(client) }
-
- before do
- client.flushdb
- end
-
- it_should_behave_like 'a flipper adapter'
-end
View
11 spec/helper.rb
@@ -1,11 +0,0 @@
-require 'rubygems'
-require 'bundler'
-require 'flipper-redis'
-
-RSpec.configure do |config|
- config.filter_run :focused => true
- config.alias_example_to :fit, :focused => true
- config.alias_example_to :xit, :pending => true
- config.run_all_when_everything_filtered = true
- config.fail_fast = true
-end

0 comments on commit c0516b2

Please sign in to comment.
Something went wrong with that request. Please try again.