Class: Gitlab::RobotsTxt::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/robots_txt/parser.rb

Constant Summary collapse

DISALLOW_REGEX =
/^disallow: /i
ALLOW_REGEX =
/^allow: /i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Parser

Returns a new instance of Parser.



11
12
13
14
15
# File 'lib/gitlab/robots_txt/parser.rb', line 11

def initialize(content)
  @raw_content = content

  @disallow_rules, @allow_rules = parse_raw_content!
end

Instance Attribute Details

#allow_rulesObject (readonly)

Returns the value of attribute allow_rules.



9
10
11
# File 'lib/gitlab/robots_txt/parser.rb', line 9

def allow_rules
  @allow_rules
end

#disallow_rulesObject (readonly)

Returns the value of attribute disallow_rules.



9
10
11
# File 'lib/gitlab/robots_txt/parser.rb', line 9

def disallow_rules
  @disallow_rules
end

Instance Method Details

#disallowed?(path) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/gitlab/robots_txt/parser.rb', line 17

def disallowed?(path)
  return false if allow_rules.any? { |rule| path =~ rule }

  disallow_rules.any? { |rule| path =~ rule }
end