diff --git a/README.md b/README.md index 4239333..79a2d12 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,15 @@ First, you need to configure where to store everything by setting a repository. Available repositories are : - `Flop::Repository::Memory` +- `Flop::Repository::Redis` To set the repository, create a new object and affect it to `Flop.repo`. ```ruby Flop.repo = Flop::Repository::Memory.new + +require 'redis' + +Flop.repo = Flop::Repository::Redis.new(Redis.new) ``` ### Features diff --git a/lib/flop.rb b/lib/flop.rb index 0178195..955939b 100644 --- a/lib/flop.rb +++ b/lib/flop.rb @@ -2,6 +2,7 @@ require 'flop/version' require 'flop/feature' require 'flop/repository/memory' +require 'flop/repository/redis' module Flop class << self diff --git a/lib/flop/feature.rb b/lib/flop/feature.rb index 765ebad..223718e 100644 --- a/lib/flop/feature.rb +++ b/lib/flop/feature.rb @@ -17,6 +17,7 @@ module Flop def set(value) repo.set(name, value) + value end def activate diff --git a/lib/flop/repository/redis.rb b/lib/flop/repository/redis.rb new file mode 100644 index 0000000..6f0d253 --- /dev/null +++ b/lib/flop/repository/redis.rb @@ -0,0 +1,24 @@ +module Flop + module Repository + class Redis + def initialize(redis, namespace = '') + @redis = redis + @namespace = namespace + end + + def get(name) + @redis.get(key(name)).to_i == 1 + end + + def set(name, value) + @redis.set(key(name), value ? 1 : 0) + end + + private + + def key(name) + [@namespace, name].join(':') + end + end + end +end