Class: GitHubPages::HealthCheck::Checkable

Inherits:
Object
  • Object
show all
Defined in:
lib/github-pages-health-check/checkable.rb

Direct Known Subclasses

Domain, Repository, Site

Constant Summary collapse

HASH_METHODS =

Array of symbolized methods to be included in the output hash

[]

Instance Method Summary collapse

Instance Method Details

#check!Object Also known as: valid!



8
9
10
# File 'lib/github-pages-health-check/checkable.rb', line 8

def check!
  raise "Not implemented"
end

#reasonObject

Returns the reason the check failed, if any



22
23
24
25
26
27
# File 'lib/github-pages-health-check/checkable.rb', line 22

def reason
  check!
  nil
rescue GitHubPages::HealthCheck::Error => e
  e
end

#to_hashObject Also known as: [], to_h



29
30
31
32
33
34
35
36
37
# File 'lib/github-pages-health-check/checkable.rb', line 29

def to_hash
  @hash ||= begin
    hash = {}
    self.class::HASH_METHODS.each do |method|
      hash[method] = public_send(method)
    end
    hash
  end
end

#to_jsonObject



41
42
43
44
# File 'lib/github-pages-health-check/checkable.rb', line 41

def to_json
  require 'json'
  to_hash.to_json
end

#to_sObject



46
47
48
# File 'lib/github-pages-health-check/checkable.rb', line 46

def to_s
  printer.simple_string
end

#to_s_prettyObject Also known as: pretty_print



50
51
52
# File 'lib/github-pages-health-check/checkable.rb', line 50

def to_s_pretty
  printer.pretty_print
end

#valid?Boolean

Runs all checks, returns true if valid, otherwise false

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/github-pages-health-check/checkable.rb', line 14

def valid?
  check!
  true
rescue GitHubPages::HealthCheck::Error
  false
end