Class: SeeingIsBelieving::Binary::Engine
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Binary::Engine
- Defined in:
- lib/seeing_is_believing/binary/engine.rb
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
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
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 66 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
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 38 def evaluate! @evaluated || begin SeeingIsBelieving.call normalized_cleaned_body, config..merge(event_handler: record_exit_events) @timed_out = false @evaluated = true end rescue Timeout::Error @timed_out = true @evaluated = true ensure return self unless $! # idk, maybe too tricky, but was really annoying putting it in three places end |
#exitstatus ⇒ Object
77 78 79 80 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 77 def exitstatus @evaluated || raise(MustEvaluateFirst.new __method__) record_exit_events.exitstatus end |
#result ⇒ Object
61 62 63 64 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 61 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
31 32 33 34 35 36 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 31 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
27 28 29 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 27 def syntax_error? code.syntax.invalid? end |
#timed_out? ⇒ Boolean
51 52 53 54 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 51 def timed_out? @evaluated || raise(MustEvaluateFirst.new __method__) !!timeout_seconds end |
#timeout_seconds ⇒ Object
56 57 58 59 |
# File 'lib/seeing_is_believing/binary/engine.rb', line 56 def timeout_seconds @evaluated || raise(MustEvaluateFirst.new __method__) record_exit_events.timeout_seconds end |