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

[].freeze

Instance Method Summary collapse

Instance Method Details

#check!Object Also known as: valid!



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

def check!
  raise "Not implemented"
end

#reasonObject

Returns the reason the check failed, if any



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

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

#to_hashObject Also known as: [], to_h



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

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

#to_json(state = nil) ⇒ Object



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

def to_json(state = nil)
  require "json"
  to_hash.to_json(state)
end

#to_sObject



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

def to_s
  printer.simple_string
end

#to_s_prettyObject Also known as: pretty_print



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

def to_s_pretty
  printer.pretty_print
end

#valid?Boolean

Runs all checks, returns true if valid, otherwise false

Returns:

  • (Boolean)


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

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