Class: ValidateWebsite::Static

Inherits:
Core
  • Object
show all
Defined in:
lib/validate_website/static.rb

Overview

Class for validation Static website

Constant Summary collapse

CONTENT_TYPES =
['text/html', 'text/xhtml+xml'].freeze

Constants inherited from Core

Core::EXIT_FAILURE_MARKUP, Core::EXIT_FAILURE_MARKUP_NOT_FOUND, Core::EXIT_FAILURE_NOT_FOUND, Core::EXIT_SUCCESS

Instance Attribute Summary collapse

Attributes inherited from Core

#errors_count, #host, #not_founds_count, #options, #site

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core

#default_cookies, #errors?, #exit_status, #not_founds?

Methods included from ColorfulMessages

#color, #error, #info, #note, #success, #warning

Constructor Details

#initialize(options = {}, validation_type = :static) ⇒ Static

Returns a new instance of Static.



11
12
13
14
# File 'lib/validate_website/static.rb', line 11

def initialize(options = {}, validation_type = :static)
  @history_count = 0
  super
end

Instance Attribute Details

#history_countObject (readonly)

Returns the value of attribute history_count.



9
10
11
# File 'lib/validate_website/static.rb', line 9

def history_count
  @history_count
end

Class Method Details

.fake_httpresponse(body, content_types = CONTENT_TYPES) ⇒ Net::HTTPResponse

Fake http response for Spidr static crawling see github.com/ruby/ruby/blob/trunk/lib/net/http/response.rb

Parameters:

  • response (String)

    body

  • content (Array)

    types

Returns:

  • (Net::HTTPResponse)

    fake http response



38
39
40
41
42
43
44
45
46
# File 'lib/validate_website/static.rb', line 38

def self.fake_httpresponse(body, content_types = CONTENT_TYPES)
  response = Net::HTTPResponse.new '1.1', 200, 'OK'
  response.instance_variable_set(:@read, true)
  response.body = body
  content_types.each do |c|
    response.add_field('content-type', c)
  end
  response
end

Instance Method Details

#crawl(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/validate_website/static.rb', line 18

def crawl(options = {})
  @options = @options.merge(options)
  @site = @options[:site]

  files = Dir.glob(@options[:pattern])
  files.each do |f|
    next unless File.file?(f)
    next if @options[:exclude].is_a?(Regexp) && @options[:exclude].match(f)
    @history_count += 1
    check_static_file(f)
  end
  print_status_line(files.size, 0, @not_founds_count, @errors_count)
end