Class: OkComputer::CheckCollection
- Inherits:
-
Object
- Object
- OkComputer::CheckCollection
- Defined in:
- lib/ok_computer/check_collection.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#display ⇒ Object
Returns the value of attribute display.
-
#registrant_name ⇒ Object
Returns the value of attribute registrant_name.
-
#skip_all ⇒ Object
Returns the value of attribute skip_all.
Instance Method Summary collapse
- #<=>(check) ⇒ Object
-
#[](key) ⇒ Object
Public: Returns a check or collection if it's in the check collection.
- #check_names ⇒ Object (also: #keys)
-
#checks ⇒ Object
(also: #values)
Public: The list of checks in the collection.
-
#deregister(name) ⇒ Object
Public: Deregisters a check from the collection.
-
#fetch(key, default = nil) ⇒ Object
Public: Returns a check or collection if it's in the check collection.
-
#initialize(display, exclude_skipped_checks = false) ⇒ CheckCollection
constructor
Public: Initialize a new CheckCollection.
-
#register(name, check) ⇒ Object
Public: Registers a check into the collection.
-
#run ⇒ Object
Public: Run the collection's checks.
- #self_and_sub_collections ⇒ Object
- #sub_collections ⇒ Object
-
#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(display, exclude_skipped_checks = false) ⇒ CheckCollection
Public: Initialize a new CheckCollection
display - the display name for the Check Collection exclude_skipped_checks - whether checks marked skip_all should be omitted
9 10 11 12 13 14 |
# File 'lib/ok_computer/check_collection.rb', line 9 def initialize(display, exclude_skipped_checks=false) self.display = display self.collection = {} self.skip_all = false @exclude_skipped_checks = exclude_skipped_checks end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
3 4 5 |
# File 'lib/ok_computer/check_collection.rb', line 3 def collection @collection end |
#display ⇒ Object
Returns the value of attribute display.
3 4 5 |
# File 'lib/ok_computer/check_collection.rb', line 3 def display @display end |
#registrant_name ⇒ Object
Returns the value of attribute registrant_name.
3 4 5 |
# File 'lib/ok_computer/check_collection.rb', line 3 def registrant_name @registrant_name end |
#skip_all ⇒ Object
Returns the value of attribute skip_all.
3 4 5 |
# File 'lib/ok_computer/check_collection.rb', line 3 def skip_all @skip_all end |
Instance Method Details
#<=>(check) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/ok_computer/check_collection.rb', line 46 def <=>(check) if check.is_a?(CheckCollection) registrant_name <=> check.registrant_name else 1 end end |
#[](key) ⇒ Object
Public: Returns a check or collection if it's in the check collection
key - a check or collection name
34 35 36 37 |
# File 'lib/ok_computer/check_collection.rb', line 34 def [](key) fetch(key) rescue KeyError end |
#check_names ⇒ Object Also known as: keys
56 57 58 |
# File 'lib/ok_computer/check_collection.rb', line 56 def check_names included_collection.keys end |
#checks ⇒ Object Also known as: values
Public: The list of checks in the collection
Returns an Array of the collection's values
42 43 44 |
# File 'lib/ok_computer/check_collection.rb', line 42 def checks included_collection.values end |
#deregister(name) ⇒ Object
Public: Deregisters a check from the collection
Returns the check
81 82 83 |
# File 'lib/ok_computer/check_collection.rb', line 81 def deregister(name) check = collection.delete(name) end |
#fetch(key, default = nil) ⇒ Object
Public: Returns a check or collection if it's in the check collection
key - a check or collection name throws a KeyError when the key is not found
25 26 27 28 29 |
# File 'lib/ok_computer/check_collection.rb', line 25 def fetch(key, default=nil) found_in = self_and_sub_collections.detect{ |c| c[key] } raise KeyError unless found_in found_in[key] end |
#register(name, check) ⇒ Object
Public: Registers a check into the collection
Returns the check
73 74 75 76 |
# File 'lib/ok_computer/check_collection.rb', line 73 def register(name, check) check.registrant_name = name collection[name] = check end |
#run ⇒ Object
Public: Run the collection's checks
17 18 19 |
# File 'lib/ok_computer/check_collection.rb', line 17 def run OkComputer.check_in_parallel ? check_in_parallel : check_in_sequence end |
#self_and_sub_collections ⇒ Object
66 67 68 |
# File 'lib/ok_computer/check_collection.rb', line 66 def self_and_sub_collections [collection] + sub_collections end |
#sub_collections ⇒ Object
62 63 64 |
# File 'lib/ok_computer/check_collection.rb', line 62 def sub_collections collection.values.select{ |c| c.is_a?(CheckCollection)} end |
#success? ⇒ Boolean
Public: Whether all the checks succeed
Returns a Boolean
108 109 110 |
# File 'lib/ok_computer/check_collection.rb', line 108 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
95 96 97 98 99 100 101 102 103 |
# File 'lib/ok_computer/check_collection.rb', line 95 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
88 89 90 |
# File 'lib/ok_computer/check_collection.rb', line 88 def to_text "#{display}\n#{checks.sort.map{ |c| "#{"\s\s" unless c.is_a?(CheckCollection)}#{c.to_text}"}.join("\n")}" end |