Class: Sc4ry::Store

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/sc4ry/store.rb

Constant Summary collapse

@@current =
:memory
@@backends =
{:memory => {:class => Sc4ry::Backends::Memory},
:redis  => {:class => Sc4ry::Backends::Redis, :config => {:host => 'localhost', :port => 6379, :db => 10 }}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



15
16
17
# File 'lib/sc4ry/store.rb', line 15

def initialize
  change_backend name: @@current 
end

Instance Attribute Details

#beObject (readonly)

Returns the value of attribute be.



12
13
14
# File 'lib/sc4ry/store.rb', line 12

def be
  @be
end

Instance Method Details

#change_backend(options) ⇒ Object



23
24
25
26
# File 'lib/sc4ry/store.rb', line 23

def change_backend(options)
  @@current = options[:name]
  @be = @@backends[@@current][:class]::new(@@backends[@@current][:config])
end

#config_backend(options) ⇒ Object



34
35
36
37
38
# File 'lib/sc4ry/store.rb', line 34

def config_backend(options)
  raise ":name is mandatory" unless options[:name]
  raise ":config is mandatory" unless options[:config]
  @@backends[options[:name]][:config] = options[:config]
end

#currentObject



19
20
21
# File 'lib/sc4ry/store.rb', line 19

def current
  return @@current
end

#register_backend(options) ⇒ Object



28
29
30
31
32
# File 'lib/sc4ry/store.rb', line 28

def register_backend(options)
  raise ":name is mandatory" unless options[:name]
  raise ":definition is mandatory" unless options[:definition]
  @@backends[options[:name]] = options[:definition]
end