Class: SiteHealth::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/site_health/configuration/configuration.rb

Overview

Holds configuration data

Defined Under Namespace

Classes: InvalidCheckerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



15
16
17
18
19
20
21
22
# File 'lib/site_health/configuration/configuration.rb', line 15

def initialize
  @checkers = Set.new(default_checkers)
  @html_proofer = nil
  @w3c = nil
  @google_page_speed_api_key = nil
  @logger = NullLogger.new
  @locale = 'en'
end

Instance Attribute Details

#checkersObject

Returns the value of attribute checkers.



13
14
15
# File 'lib/site_health/configuration/configuration.rb', line 13

def checkers
  @checkers
end

#google_page_speed_api_keyObject (readonly)

Returns the value of attribute google_page_speed_api_key.



13
14
15
# File 'lib/site_health/configuration/configuration.rb', line 13

def google_page_speed_api_key
  @google_page_speed_api_key
end

#localeObject (readonly)

Returns the value of attribute locale.



13
14
15
# File 'lib/site_health/configuration/configuration.rb', line 13

def locale
  @locale
end

#loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/site_health/configuration/configuration.rb', line 13

def logger
  @logger
end

Instance Method Details

#default_checkersArray<Checker>

Returns array of default checkers to run.

Returns:

  • (Array<Checker>)

    array of default checkers to run



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/site_health/configuration/configuration.rb', line 72

def default_checkers
  %i[
    facebook_share_link
    missing_title
    missing_description
    redirect
    xml
    json_syntax
    page_not_found
  ].map! { |name| SiteHealth.load_checker(name) }
end

#html_proofer {|the| ... } ⇒ HTMLProoferConfiguration

Returns the current configuration.

Yield Parameters:

Returns:



35
36
37
38
39
# File 'lib/site_health/configuration/configuration.rb', line 35

def html_proofer
  @html_proofer ||= HTMLProoferConfiguration.new
  yield(@html_proofer) if block_given?
  @html_proofer
end

#register_checker(checker) ⇒ Checker

Returns the registered checker.

Parameters:

  • checker (Checker, String, Symbol)

    additional checker to run can also be the name of an existing checker

Returns:

  • (Checker)

    the registered checker



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/site_health/configuration/configuration.rb', line 58

def register_checker(checker)
  if [String, Symbol].include?(checker.class)
    checker = SiteHealth.load_checker(checker)
  end

  unless checker.respond_to?(:check) || checker.instance_methods.include?(:check)
    raise(InvalidCheckerError, 'checker must implement #check')
  end

  @checkers << checker
  checker
end

#w3c {|the| ... } ⇒ W3CValidatorsConfiguration

Returns the current configuration.

Yield Parameters:

Returns:



43
44
45
46
47
# File 'lib/site_health/configuration/configuration.rb', line 43

def w3c
  @w3c ||= W3CValidatorsConfiguration.new
  yield(@w3c) if block_given?
  @w3c
end