Add abstract Repository class

The default behaviour is to raise an exception if set or get methods are
not defined in the repository.
master
Guillaume Dott 2014-09-01 17:41:35 +02:00
parent 57f248b483
commit 30d1958e46
5 changed files with 39 additions and 4 deletions

View File

@ -1,6 +1,8 @@
require 'flop/version' require 'flop/version'
require 'flop/feature' require 'flop/feature'
require 'flop/repository'
require 'flop/repository/memory' require 'flop/repository/memory'
require 'flop/repository/redis' require 'flop/repository/redis'

View File

@ -0,0 +1,14 @@
module Flop
class Repository
def get(name)
raise GetNotImplemented
end
def set(name, value)
raise SetNotImplemented
end
GetNotImplemented = Class.new(StandardError)
SetNotImplemented = Class.new(StandardError)
end
end

View File

@ -1,6 +1,6 @@
module Flop module Flop
module Repository class Repository
class Memory class Memory < Flop::Repository
def initialize def initialize
@features = Hash.new(false) @features = Hash.new(false)
end end

View File

@ -1,6 +1,6 @@
module Flop module Flop
module Repository class Repository
class Redis class Redis < Flop::Repository
def initialize(redis, namespace = '') def initialize(redis, namespace = '')
@redis = redis @redis = redis
@namespace = namespace @namespace = namespace

View File

@ -0,0 +1,19 @@
require 'test_helper'
class Flop::RepositoryTest < Minitest::Test
def setup
@repo = Flop::Repository.new
end
def test_get_raises_exception
assert_raises(Flop::Repository::GetNotImplemented) do
@repo.get(:test)
end
end
def test_set_raises_exception
assert_raises(Flop::Repository::SetNotImplemented) do
@repo.set(:test, true)
end
end
end