Class: Moneta::Builder

Inherits:
Object
  • Object
show all
Includes:
Middleware
Defined in:
lib/moneta/builder.rb

Instance Method Summary collapse

Methods included from Middleware

#[], #[]=, #build, #clear, #close, #delete, #fetch, included, #key?, #store, #update_key

Constructor Details

#initialize(&block) ⇒ Builder

Returns a new instance of Builder.



53
54
55
56
57
# File 'lib/moneta/builder.rb', line 53

def initialize(&block)
  @middlewares = []
  @adapter     = nil
  instance_eval(&block)
end

Instance Method Details

#run(adapter, *args, &block) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/moneta/builder.rb', line 63

def run(adapter, *args, &block)
  @adapter = adapter.new(*args, &block)

  @middlewares.reverse.each do |middleware|
    @adapter = middleware.build(@adapter)
  end
end

#use(middleware, *args, &block) ⇒ Object



59
60
61
# File 'lib/moneta/builder.rb', line 59

def use(middleware, *args, &block)
  @middlewares << middleware.build(*args, &block)
end