Class: SeeingIsBelieving::Binary::Engine

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

Defined Under Namespace

Modules: ToggleMark

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



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



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.lib_options.merge(event_handler: record_exit_events)
  )
  self
end

#exitstatusObject



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

#resultObject



113
114
115
116
# File 'lib/seeing_is_believing/binary/engine.rb', line 113

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



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

#syntax_error?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/seeing_is_believing/binary/engine.rb', line 84

def syntax_error?
  code.syntax.invalid?
end

#timed_out?Boolean

Returns:

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



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_markObject



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.annotator_options.alignment_strategy.new(normalized_cleaned_body),
    options:            config.annotator_options.to_h,
  )
  toggled.chomp! if missing_newline?
  toggled
end