Module: Robotron

Defined in:
lib/robotron.rb,
lib/robotron/version.rb

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/robotron.rb', line 3

def call(env)
  body = File.read(robots_path)

  [200, default_headers, [body]]
rescue Errno::ENOENT
  [200, default_headers, [default_body]]
end

.default_bodyObject



23
24
25
# File 'lib/robotron.rb', line 23

def default_body
  "User-Agent: *\nDisallow: /"
end

.default_headersObject



27
28
29
30
31
32
# File 'lib/robotron.rb', line 27

def default_headers
  {
    'Content-Type' => 'text/plain',
    'Cache-Control' => 'public, max-age=31557600'
  }
end

.environmentObject



11
12
13
# File 'lib/robotron.rb', line 11

def environment
  ENV['RACK_ENV'] || 'development'
end

.robots_directoryObject



15
16
17
# File 'lib/robotron.rb', line 15

def robots_directory
  defined?(Rails) ? Rails.root.join('config') : File.join('spec')
end

.robots_pathObject



19
20
21
# File 'lib/robotron.rb', line 19

def robots_path
  File.join(robots_directory, "robots.txt.#{ environment }")
end