/usr/lib/ruby/vendor_ruby/rack/moneta_store.rb is in ruby-moneta 0.7.20-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | require 'moneta'
module Rack
# A Rack middleware that inserts a Moneta store in the environment
# and supports per-request caching via the the option `:cache => true`.
#
# @example config.ru
# # Add Rack::MonetaStore somewhere in your rack stack
# use Rack::MonetaStore, :Memory, :cache => true
#
# run lambda { |env|
# env['rack.moneta_store'] # is a Moneta store with per-request caching
# }
#
# @example config.ru
# # Pass it a block like the one passed to Moneta.build
# use Rack::MonetaStore do
# use :Transformer, :value => :zlib
# adapter :Cookie
# end
#
# run lambda { |env|
# env['rack.moneta_store'] # is a Moneta store without caching
# }
#
# @api public
class MonetaStore
def initialize(app, store = nil, options = {}, &block)
@app = app
@cache = options.delete(:cache)
if block
raise ArgumentError, 'Use either block or options' unless options.empty?
@store = ::Moneta.build(&block)
else
raise ArgumentError, 'Block or argument store is required' unless @store = store
@store = ::Moneta.new(@store, options) if Symbol === @store
end
end
def call(env)
env['rack.moneta_store'] = @cache ? ::Moneta::Cache.new(:cache => ::Moneta::Adapters::Memory.new, :adapter => @store) : @store
@app.call(env)
end
end
end
|