Class: Rack::MonetaStore
- Inherits:
-
Object
- Object
- Rack::MonetaStore
- Defined in:
- lib/rack/moneta_store.rb
Overview
A Rack middleware that inserts a Moneta store in the environment and supports per-request caching via the the option ‘:cache => true`.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, store = nil, options = {}, &block) ⇒ MonetaStore
constructor
A new instance of MonetaStore.
Constructor Details
#initialize(app, store = nil, options = {}, &block) ⇒ MonetaStore
Returns a new instance of MonetaStore.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rack/moneta_store.rb', line 28 def initialize(app, store = nil, = {}, &block) @app = app @cache = .delete(:cache) if block raise ArgumentError, 'Use either block or options' unless .empty? @store = ::Moneta.build(&block) else raise ArgumentError, 'Block or argument store is required' unless @store = store @store = ::Moneta.new(@store, ) if Symbol === @store end end |
Instance Method Details
#call(env) ⇒ Object
40 41 42 43 |
# File 'lib/rack/moneta_store.rb', line 40 def call(env) env['rack.moneta_store'] = @cache ? ::Moneta::Cache.new(:cache => ::Moneta::Adapters::Memory.new, :backend => @store) : @store @app.call(env) end |