Class: OkComputer::CheckCollection
- Inherits:
-
Object
- Object
- OkComputer::CheckCollection
- Defined in:
- lib/ok_computer/check_collection.rb
Instance Attribute Summary collapse
-
#registry ⇒ Object
Returns the value of attribute registry.
Instance Method Summary collapse
-
#checks ⇒ Object
Public: The list of checks in the collection.
-
#initialize(registry = {}) ⇒ CheckCollection
constructor
Public: Initialize a new CheckCollection.
-
#run ⇒ Object
Public: Run the registry’s checks.
-
#success? ⇒ Boolean
Public: Whether all the checks succeed.
-
#to_json(*args) ⇒ Object
Public: The JSON of each check in the collection.
-
#to_text ⇒ Object
Public: The text of each check in the collection.
Constructor Details
#initialize(registry = {}) ⇒ CheckCollection
Public: Initialize a new CheckCollection
registry - a Hash of checks, with keys being unique names and values
being Check instances
9 10 11 |
# File 'lib/ok_computer/check_collection.rb', line 9 def initialize(registry={}) self.registry = registry end |
Instance Attribute Details
#registry ⇒ Object
Returns the value of attribute registry.
3 4 5 |
# File 'lib/ok_computer/check_collection.rb', line 3 def registry @registry end |
Instance Method Details
#checks ⇒ Object
Public: The list of checks in the collection
Returns an Array of the registry’s values
21 22 23 |
# File 'lib/ok_computer/check_collection.rb', line 21 def checks registry.values end |
#run ⇒ Object
Public: Run the registry’s checks
14 15 16 |
# File 'lib/ok_computer/check_collection.rb', line 14 def run checks.each(&:run) end |
#success? ⇒ Boolean
Public: Whether all the checks succeed
Returns a Boolean
48 49 50 |
# File 'lib/ok_computer/check_collection.rb', line 48 def success? checks.all?(&:success?) end |
#to_json(*args) ⇒ Object
Public: The JSON of each check in the collection
Returns a String containing a JSON array of hashes
35 36 37 38 39 40 41 42 43 |
# File 'lib/ok_computer/check_collection.rb', line 35 def to_json(*args) # smooshing their #to_json objects into one JSON hash combined = {} checks.each do |check| combined.merge!(JSON.parse(check.to_json)) end combined.to_json end |
#to_text ⇒ Object
Public: The text of each check in the collection
Returns a String
28 29 30 |
# File 'lib/ok_computer/check_collection.rb', line 28 def to_text checks.map(&:to_text).join("\n") end |