Class: Speck::Check
- Inherits:
-
Object
- Object
- Speck::Check
- Defined in:
- lib/speck/check.rb
Overview
Represents a queued thing to be checked of some sort, within a Speck.
Instance Attribute Summary collapse
-
#description ⇒ Object
A description for the check.
-
#lambda ⇒ Object
A block to be executed.
-
#status ⇒ Object
The status of the
Check.
Instance Method Summary collapse
-
#execute ⇒ Object
Executes this
Check, raising an error if the block returns nil or false. -
#initialize(lambda, description = "<undocumented>") ⇒ Check
constructor
A new instance of Check.
-
#success? ⇒ Boolean
Checks the truthiness of this
Check’sstatus.
Constructor Details
#initialize(lambda, description = "<undocumented>") ⇒ Check
40 41 42 43 |
# File 'lib/speck/check.rb', line 40 def initialize(lambda, description = "<undocumented>") @lambda = lambda @description = description end |
Instance Attribute Details
#description ⇒ Object
A description for the check. Usually a relevant line of code.
11 12 13 |
# File 'lib/speck/check.rb', line 11 def description @description end |
#lambda ⇒ Object
A block to be executed.
7 8 9 |
# File 'lib/speck/check.rb', line 7 def lambda @lambda end |
#status ⇒ Object
The status of the Check. nil indicates the Check hasn’t been
executed, and true or false indicate the success of the latest
execution.
17 18 19 |
# File 'lib/speck/check.rb', line 17 def status @status end |
Instance Method Details
#execute ⇒ Object
Executes this Check, raising an error if the block returns nil or
false.
55 56 57 58 59 |
# File 'lib/speck/check.rb', line 55 def execute @lambda.call.tap {|result| @status = result ? result : false } raise Exception::CheckFailed unless success? self end |
#success? ⇒ Boolean
Checks the truthiness of this Check’s status.
21 22 23 |
# File 'lib/speck/check.rb', line 21 def success? !!status end |