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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RegexHostChecker

#valid?

Methods inherited from HostChecker

all, #call, #error_response, matching, #valid?

Constructor Details

#initialize(pattern) ⇒ WildcardHostChecker

Returns a new instance of WildcardHostChecker.



80
81
82
83
84
85
86
# File 'lib/guillotine/host_checkers.rb', line 80

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.



78
79
80
# File 'lib/guillotine/host_checkers.rb', line 78

def host
  @host
end

#patternObject (readonly)

Returns the value of attribute pattern.



78
79
80
# File 'lib/guillotine/host_checkers.rb', line 78

def pattern
  @pattern
end

Class Method Details

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

Returns:

  • (Boolean)


70
71
72
# File 'lib/guillotine/host_checkers.rb', line 70

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