Class: Roboto::ContentProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/roboto/content_provider.rb

Overview

provides the content of effective robots.txt file

Instance Method Summary collapse

Instance Method Details

#contents(custom_binding = nil) ⇒ String

Reads the contents of the effective robots.txt file

Returns:

  • (String)

    the contents of the effective robots.txt file



8
9
10
11
12
13
14
15
16
# File 'lib/roboto/content_provider.rb', line 8

def contents(custom_binding = nil)
  return @contents unless @contents.nil?

  @contents = File.read(path)
  if path.extname == '.erb'
    @contents = ERB.new(@contents, nil, '>').result(custom_binding ? custom_binding : binding)
  end
  @contents
end

#pathPath

Determines the most relevant robots.txt file.

It checks for the paths in the following order

  1. Rails.root/config/robots/.txt (ie production.txt)
  2. Rails.root/config/robots/default.txt
  3. The default, blank robots.txt provided by the gem

Returns:

  • (Path)

    the path of the effective robots.txt file



26
27
28
29
30
31
32
33
34
35
# File 'lib/roboto/content_provider.rb', line 26

def path
  lookup_paths.each do |f|
    if FileTest.exist?(f)
      return f
    end
  end

  #this should never occur because we define a default in the gem
  raise "Robots file not found"
end