Class: Moneta::Builder Private
- Inherits:
-
Object
- Object
- Moneta::Builder
- Defined in:
- lib/moneta/builder.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Builder implements the DSL to build a stack of Moneta store proxies
Instance Method Summary collapse
-
#adapter(name, options = {}, &block) ⇒ Object
Add adapter to stack.
-
#build ⇒ Object
Build proxy stack.
-
#initialize(&block) ⇒ Builder
constructor
private
A new instance of Builder.
-
#use(proxy, options = {}, &block) ⇒ Object
Add proxy to stack.
Constructor Details
#initialize(&block) ⇒ Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Builder.
5 6 7 8 9 |
# File 'lib/moneta/builder.rb', line 5 def initialize(&block) raise ArgumentError, 'No block given' unless block_given? @proxies = [] instance_eval(&block) end |
Instance Method Details
#adapter(name, options = {}, &block) ⇒ Object
Add adapter to stack
39 40 41 |
# File 'lib/moneta/builder.rb', line 39 def adapter(name, = {}, &block) use(Adapters.const_get(name), , &block) end |
#build ⇒ Object
Build proxy stack
14 15 16 17 18 19 20 |
# File 'lib/moneta/builder.rb', line 14 def build klass, , block = @proxies.first @proxies[1..-1].inject([klass.new(, &block)]) do |stores, proxy| klass, , block = proxy stores << klass.new(stores.last, , &block) end end |
#use(proxy, options = {}, &block) ⇒ Object
Add proxy to stack
27 28 29 30 31 32 |
# File 'lib/moneta/builder.rb', line 27 def use(proxy, = {}, &block) proxy = Moneta.const_get(proxy) if Symbol === proxy raise ArgumentError, 'You must give a Class or a Symbol' unless Class === proxy @proxies.unshift [proxy, , block] nil end |