Class: SeeingIsBelieving::Binary::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/seeing_is_believing/binary/engine.rb

Instance Method Summary collapse

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_bodyObject



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.annotator_options.to_h
    annotated.chomp! if missing_newline?
    annotated
  end
end

#cleaned_bodyObject



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.lib_options.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

#exitstatusObject



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

#resultObject



61
62
63
64
# File 'lib/seeing_is_believing/binary/engine.rb', line 61

def result
  @evaluated || raise(MustEvaluateFirst.new __method__)
  config.lib_options.event_handler.result # The stream handler will not have a result (implies this was used wrong)
end

#syntax_errorObject



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.error_message,
                         filename:    config.lib_options.filename
end

#syntax_error?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/seeing_is_believing/binary/engine.rb', line 27

def syntax_error?
  code.syntax.invalid?
end

#timed_out?Boolean

Returns:

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



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