Class: OkComputer::Check

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

Constant Summary collapse

CheckNotDefined =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#failure_occurredObject

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



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

def failure_occurred
  @failure_occurred
end

#messageObject

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



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

def message
  @message
end

#registrant_nameObject

to be set by Registry upon registration



4
5
6
# File 'lib/ok_computer/check.rb', line 4

def registrant_name
  @registrant_name
end

Instance Method Details

#clearObject

Public: Clear any prior failures



62
63
64
65
# File 'lib/ok_computer/check.rb', line 62

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

#mark_failureObject

Public: Mark that this check has failed in some way



50
51
52
# File 'lib/ok_computer/check.rb', line 50

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



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

def mark_message(message)
  self.message = message
end

#runObject

Public: Run the check



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

def run
  clear
  check
end

#success?Boolean

Public: Whether the check passed

Returns a boolean

Returns:

  • (Boolean)


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

def success?
  not failure_occurred
end

#to_json(*args) ⇒ Object

Public: The JSON output of performing the check

Returns a String containing JSON



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

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_textObject

Public: The text output of performing the check

Returns a String



28
29
30
31
# File 'lib/ok_computer/check.rb', line 28

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