Class: Garner::Middleware::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/garner/middleware/base.rb

Direct Known Subclasses

Cache::Bust

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • app (Rack Application)

    The standard argument for a Rack middleware.

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

    A hash of options, simply stored for use by subclasses.



9
10
11
12
# File 'lib/garner/middleware/base.rb', line 9

def initialize(app, options = {})
  @app = app
  @options = default_options.merge(options)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/garner/middleware/base.rb', line 5

def app
  @app
end

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/garner/middleware/base.rb', line 5

def env
  @env
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/garner/middleware/base.rb', line 5

def options
  @options
end

Instance Method Details

#afterResponse?

This method is abstract.

Called after the application is called in the middleware lifecycle.

Returns:

  • (Response, nil)

    a Rack SPEC response or nil to call the application afterwards.



34
# File 'lib/garner/middleware/base.rb', line 34

def after; end

#beforeObject

This method is abstract.

Called before the application is called in the middleware lifecycle.



29
# File 'lib/garner/middleware/base.rb', line 29

def before; end

#call(env) ⇒ Object



16
17
18
# File 'lib/garner/middleware/base.rb', line 16

def call(env)
  dup.call!(env)
end

#call!(env) ⇒ Object



20
21
22
23
24
25
# File 'lib/garner/middleware/base.rb', line 20

def call!(env)
  @env = env
  before
  @app_response = @app.call(@env)
  after || @app_response
end

#default_optionsObject



14
# File 'lib/garner/middleware/base.rb', line 14

def default_options; {} end

#requestObject



36
37
38
# File 'lib/garner/middleware/base.rb', line 36

def request
  Rack::Request.new(self.env)
end

#responseObject



40
41
42
# File 'lib/garner/middleware/base.rb', line 40

def response
  Rack::Response.new(@app_response)
end