Class: Lawnchair::StorageEngine::Composite
- Inherits:
-
Object
- Object
- Lawnchair::StorageEngine::Composite
- Defined in:
- lib/storage_engine/composite.rb
Instance Attribute Summary collapse
-
#storage_engines ⇒ Object
readonly
Returns the value of attribute storage_engines.
Instance Method Summary collapse
- #fetch(key, options, &block) ⇒ Object
-
#initialize(*args) ⇒ Composite
constructor
A new instance of Composite.
- #register_storage_engine(storage_engine) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Composite
Returns a new instance of Composite.
6 7 8 9 10 11 |
# File 'lib/storage_engine/composite.rb', line 6 def initialize(*args) @storage_engines = [] args.each do |arg| register_storage_engine arg end end |
Instance Attribute Details
#storage_engines ⇒ Object (readonly)
Returns the value of attribute storage_engines.
4 5 6 |
# File 'lib/storage_engine/composite.rb', line 4 def storage_engines @storage_engines end |
Instance Method Details
#fetch(key, options, &block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/storage_engine/composite.rb', line 18 def fetch(key, , &block) raise "No Storage Engines Configured" if storage_engines.empty? value, index = find_in_storage(key, ) value ||= yield place_in_storage(key, value, , index) end |
#register_storage_engine(storage_engine) ⇒ Object
13 14 15 16 |
# File 'lib/storage_engine/composite.rb', line 13 def register_storage_engine(storage_engine) klass = storage_engine == :redis ? "Redis" : "InProcess" storage_engines << Object.module_eval("Lawnchair::StorageEngine::#{klass}") end |