Class: OKComputer::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/okcomputer/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_occurredObject

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



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

def failure_occurred
  @failure_occurred
end

#messageObject

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



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

def message
  @message
end

#registrant_nameObject

to be set by Registry upon registration



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

def registrant_name
  @registrant_name
end

Instance Method Details

#clearObject

Public: Clear any prior failures



69
70
71
72
# File 'lib/okcomputer/check.rb', line 69

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

#mark_failureObject

Public: Mark that this check has failed in some way



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

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



64
65
66
# File 'lib/okcomputer/check.rb', line 64

def mark_message(message)
  self.message = message
end

#runObject

Public: Run the check



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

def run
  clear
  check
end

#success?Boolean

Public: Whether the check passed

Returns a boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/okcomputer/check.rb', line 52

def success?
  not failure_occurred
end

#to_json(*args) ⇒ Object

Public: The JSON output of performing the check

Returns a String containing JSON



43
44
45
46
47
# File 'lib/okcomputer/check.rb', line 43

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}.to_json
end

#to_textObject

Public: The text output of performing the check

Returns a String



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

def to_text
  "#{registrant_name}: #{message}"
end