Class: OkComputer::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/ok_computer/check.rb

Constant Summary collapse

CALL_DEPRECATION_MESSAGE =
"Deprecation warning: Please define #check rather than defining #call"
CheckNotDefined =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#failure_occurred ⇒ Object

nil by default, only set to true if the check deems itself failed



8
9
10
# File 'lib/ok_computer/check.rb', line 8

def failure_occurred
  @failure_occurred
end

#message ⇒ Object

nil by default, set by #check to control the output



10
11
12
# File 'lib/ok_computer/check.rb', line 10

def message
  @message
end

#registrant_name ⇒ Object

to be set by Registry upon registration



6
7
8
# File 'lib/ok_computer/check.rb', line 6

def registrant_name
  @registrant_name
end

Instance Method Details

#clear ⇒ Object

Public: Clear any prior failures



70
71
72
73
# File 'lib/ok_computer/check.rb', line 70

def clear
  self.failure_occurred = false
  self.message = nil
end

#mark_failure ⇒ Object

Public: Mark that this check has failed in some way



58
59
60
# File 'lib/ok_computer/check.rb', line 58

def mark_failure
  self.failure_occurred = true
end

#mark_message(message) ⇒ Object

Public: Capture the desired message to display

message - Text of the message to display for this check



65
66
67
# File 'lib/ok_computer/check.rb', line 65

def mark_message(message)
  self.message = message
end

#run ⇒ Object

Public: Run the check



13
14
15
16
# File 'lib/ok_computer/check.rb', line 13

def run
  clear
  check
end

#success? ⇒ Boolean

Public: Whether the check passed

Returns a boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ok_computer/check.rb', line 53

def success?
  not failure_occurred
end

#to_json(*args) ⇒ Object

Public: The JSON output of performing the check

Returns a String containing JSON



44
45
46
47
48
# File 'lib/ok_computer/check.rb', line 44

def to_json(*args)
  # NOTE swallowing the arguments that Rails passes by default since we don't care. This may prove to be a bad idea
  # Rails passes stuff like this: {:prefixes=>["ok_computer", "application"], :template=>"show", :layout=>#<Proc>}]
  {registrant_name => {:message => message, :success => success?}}.to_json
end

#to_text ⇒ Object

Public: The text output of performing the check

Returns a String



36
37
38
39
# File 'lib/ok_computer/check.rb', line 36

def to_text
  passfail = success? ? "PASSED" : "FAILED"
  "#{registrant_name}: #{passfail} #{message}"
end