Add abstract Repository class
The default behaviour is to raise an exception if set or get methods are not defined in the repository.master
parent
57f248b483
commit
30d1958e46
|
@ -1,6 +1,8 @@
|
|||
require 'flop/version'
|
||||
|
||||
require 'flop/feature'
|
||||
|
||||
require 'flop/repository'
|
||||
require 'flop/repository/memory'
|
||||
require 'flop/repository/redis'
|
||||
|
||||
|
|
|
@ -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
|
|
@ -1,6 +1,6 @@
|
|||
module Flop
|
||||
module Repository
|
||||
class Memory
|
||||
class Repository
|
||||
class Memory < Flop::Repository
|
||||
def initialize
|
||||
@features = Hash.new(false)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Flop
|
||||
module Repository
|
||||
class Redis
|
||||
class Repository
|
||||
class Redis < Flop::Repository
|
||||
def initialize(redis, namespace = '')
|
||||
@redis = redis
|
||||
@namespace = namespace
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue