Class: Guillotine::WildcardHostChecker

Inherits:
RegexHostChecker show all
Defined in:
lib/guillotine/host_checkers.rb

Instance Attribute Summary collapse

Attributes inherited from RegexHostChecker

#regex

Attributes inherited from HostChecker

#error, #error_response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RegexHostChecker

#valid?

Methods inherited from HostChecker

all, #call, matching, #valid?

Constructor Details

#initialize(pattern) ⇒ WildcardHostChecker

Returns a new instance of WildcardHostChecker.



76
77
78
79
80
81
82
# File 'lib/guillotine/host_checkers.rb', line 76

def initialize(pattern)
  @pattern = pattern
  @host = self.class.host_from(pattern)
  @regex = %r{(^|\.)#{Regexp.escape @host}$}
  super(@regex)
  @error = "URL must be from #{@host}"
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



74
75
76
# File 'lib/guillotine/host_checkers.rb', line 74

def host
  @host
end

#patternObject (readonly)

Returns the value of attribute pattern.



74
75
76
# File 'lib/guillotine/host_checkers.rb', line 74

def pattern
  @pattern
end

Class Method Details

.match?(arg) ⇒ Boolean Also known as: host_from

Returns:

  • (Boolean)


66
67
68
# File 'lib/guillotine/host_checkers.rb', line 66

def self.match?(arg)
  arg.to_s =~ /^\*\.([\w\.]+)$/ && $1
end