Class: Rack::Robotz

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/robotz/middleware.rb

Constant Summary collapse

VERSION =
'0.0.4'

Instance Method Summary collapse

Constructor Details

#initialize(app, items = {"User-Agent" => "*", "Disallow" => "/"}) ⇒ Robotz

Returns a new instance of Robotz.



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

def initialize(app, items = {"User-Agent" => "*", "Disallow" => "/"})
  @app = app
  @items = items
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rack/robotz/middleware.rb', line 16

def call(env)
  if env['PATH_INFO'] == '/robots.txt'
    [200, { 'Content-Type' => 'text/plain' }, [to_s]]
  else
    @app.call(env)
  end
end

#to_sObject



12
13
14
# File 'lib/rack/robotz/middleware.rb', line 12

def to_s
  @items.map { |key, value| "#{key}: #{value}" }.join("\n")
end