Class: Footprint::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/footprint/middleware/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ Middleware

Returns a new instance of Middleware.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/footprint/middleware/logger.rb', line 10

def initialize(app, &block)

  @app = app

  set Footprint::Log::Basic, STDOUT

  @app.class.send(:define_method, :logger,
                  Proc.new do
                    @env[:footprint_logger]
                  end)

  self.instance_eval &block if block
end

Instance Attribute Details

#appObject

Returns the value of attribute app.



8
9
10
# File 'lib/footprint/middleware/logger.rb', line 8

def app
  @app
end

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/footprint/middleware/logger.rb', line 8

def logger
  @logger
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
# File 'lib/footprint/middleware/logger.rb', line 24

def call(env)
  env[:footprint_logger] = @logger
  @app.call env
end

#set(clazz, *args) ⇒ Object



29
30
31
# File 'lib/footprint/middleware/logger.rb', line 29

def set clazz, *args
  @logger = clazz.send(:new, *args)
end