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
START_MESSAGE_TYPE =
'files'

Constants inherited from Core

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

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.



14
15
16
17
18
# File 'lib/validate_website/static.rb', line 14

def initialize(options = {}, validation_type = :static)
  @history_count = 0
  super
  start_message("#{START_MESSAGE_TYPE} in #{Dir.pwd} (#{@site} as site)")
end

Instance Attribute Details

#history_countObject (readonly)

Returns the value of attribute history_count.



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

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



43
44
45
46
47
48
49
50
51
# File 'lib/validate_website/static.rb', line 43

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: {})


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/validate_website/static.rb', line 22

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

  files = Dir.glob(@options[:pattern])
  files.each do |file|
    next unless File.file?(file)
    next if @options[:exclude]&.match(file)

    @history_count += 1
    check_static_file(file)
  end
  print_status_line(files.size, 0, @not_founds_count, @errors_count)
end