Class: OkComputer::CheckCollection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#registryObject

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

#checksObject

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

#runObject

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

Returns:

  • (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_textObject

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