Class: SeeingIsBelieving::Binary::Engine
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Binary::Engine
- Defined in:
- lib/seeing_is_believing/binary/engine.rb
Defined Under Namespace
Modules: ToggleMark
Instance Method Summary collapse
- #annotated_body ⇒ Object
- #cleaned_body ⇒ Object
- #evaluate! ⇒ Object
- #exitstatus ⇒ Object
-
#initialize(config) ⇒ Engine
constructor
A new instance of Engine.
- #result ⇒ Object
- #syntax_error ⇒ Object
- #syntax_error? ⇒ Boolean
- #timed_out? ⇒ Boolean
- #timeout_seconds ⇒ Object
- #toggled_mark ⇒ Object
Constructor Details
#initialize(config) ⇒ Engine
Returns a new instance of Engine.
15 16 17 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 15 def initialize(config) self.config = config end |
Instance Method Details
#annotated_body ⇒ Object
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 118 def annotated_body @annotated_body ||= begin @evaluated || raise(MustEvaluateFirst.new __method__) annotated = config.annotator.call normalized_cleaned_body, result, config..to_h annotated.chomp! if missing_newline? annotated end end |
#cleaned_body ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 19 def cleaned_body @cleaned_body ||= if missing_newline? normalized_cleaned_body.chomp else normalized_cleaned_body end end |
#evaluate! ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 95 def evaluate! @evaluated ||= !!SeeingIsBelieving.call( normalized_cleaned_body, config..merge(event_handler: record_exit_events) ) self end |
#exitstatus ⇒ Object
129 130 131 132 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 129 def exitstatus @evaluated || raise(MustEvaluateFirst.new __method__) record_exit_events.exitstatus end |
#result ⇒ Object
113 114 115 116 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 113 def result @evaluated || raise(MustEvaluateFirst.new __method__) config..event_handler.result # The stream handler will not have a result (implies this was used wrong) end |
#syntax_error ⇒ Object
88 89 90 91 92 93 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 88 def syntax_error return unless syntax_error? SyntaxErrorMessage.new line_number: code.syntax.line_number, explanation: code.syntax., filename: config..filename end |
#syntax_error? ⇒ Boolean
84 85 86 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 84 def syntax_error? code.syntax.invalid? end |
#timed_out? ⇒ Boolean
103 104 105 106 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 103 def timed_out? @evaluated || raise(MustEvaluateFirst.new __method__) !!timeout_seconds end |
#timeout_seconds ⇒ Object
108 109 110 111 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 108 def timeout_seconds @evaluated || raise(MustEvaluateFirst.new __method__) record_exit_events.timeout_seconds end |
#toggled_mark ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 70 def toggled_mark body = config.body body += "\n" if missing_newline? toggled = ToggleMark.call( body: body, line: config.toggle_mark, markers: config.markers, alignment_strategy: config..alignment_strategy.new(normalized_cleaned_body), options: config..to_h, ) toggled.chomp! if missing_newline? toggled end |