Class: Rack::Favicon

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/favicon.rb,
lib/rack/favicon/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Favicon.



7
8
9
10
# File 'lib/rack/favicon.rb', line 7

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

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rack/favicon.rb', line 12

def call(env)
  status, headers, response = @app.call(env)

  if env['PATH_INFO'] =~ (/favicon\.ico$/)
    if @options[:image]
      path = ::File.join(Dir.getwd, @options[:image])
    else
      path = ::File.expand_path('../favicon.ico', __FILE__)
    end
    response = [ ::File.open(path, 'rb') { |file| file.read } ]
  end
  [status, headers, response]
end