Class: Moneta::Builder Private

Inherits:
Object
  • Object
show all
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

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.

Raises:

  • (ArgumentError)

14
15
16
17
18
# File 'lib/moneta/builder.rb', line 14

def initialize(&block)
  raise ArgumentError, 'No block given' unless block_given?
  @proxies = []
  instance_eval(&block)
end

Instance Method Details

#adapter(name, options = {}, &block) ⇒ Object

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.

Add adapter to stack

Parameters:

  • name (Symbol)

    Name of adapter class

  • options (Hash) (defaults to: {})

    Options hash


35
36
37
# File 'lib/moneta/builder.rb', line 35

def adapter(name, options = {}, &block)
  use(Adapters.const_get(name), options, &block)
end

#buildObject

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.


6
7
8
9
10
11
12
# File 'lib/moneta/builder.rb', line 6

def build
  klass, options, block = @proxies.first
  @proxies[1..-1].inject([klass.new(options, &block)]) do |stores, proxy|
    klass, options, block = proxy
    stores << klass.new(stores.last, options, &block)
  end
end

#use(proxy, options = {}, &block) ⇒ Object

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.

Add proxy to stack

Parameters:

  • proxy (Symbol or Class)

    Name of proxy class or proxy class

  • options (Hash) (defaults to: {})

    Options hash

Raises:

  • (ArgumentError)

24
25
26
27
28
29
# File 'lib/moneta/builder.rb', line 24

def use(proxy, options = {}, &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, options, block]
  nil
end