Class: Rack::MonetaCookies
- Inherits:
-
Object
- Object
- Rack::MonetaCookies
- Defined in:
- lib/rack/moneta_cookies.rb
Overview
A Rack middleware that was made to reuse all moneta transformers on the cookie hash.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}, &block) ⇒ MonetaCookies
constructor
A new instance of MonetaCookies.
Constructor Details
#initialize(app, options = {}, &block) ⇒ MonetaCookies
Returns a new instance of MonetaCookies.
38 39 40 41 42 43 44 45 46 |
# File 'lib/rack/moneta_cookies.rb', line 38 def initialize(app, = {}, &block) @app, @pool = app, [] if block raise ArgumentError, 'Use either block or options' unless .empty? @builder = Moneta::Builder.new(&block) else @builder = Moneta::Builder.new { adapter :Cookie, } end end |
Instance Method Details
#call(env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rack/moneta_cookies.rb', line 48 def call(env) stores = @pool.pop || @builder.build env['rack.moneta_cookies'] = env['rack.request.cookie_hash'] = stores.last env['rack.request.cookie_string'] = env['HTTP_COOKIE'] stores.first.reset(Rack::Utils.parse_query(env['HTTP_COOKIE'])) status, headers, body = @app.call(env) stores.first..each do |key, | if == nil Rack::Utils.(headers, key) else Rack::Utils.(headers, key, ) end end @pool << stores [status, headers, body] end |