Class: SeeingIsBelieving::Binary::AddAnnotations

Inherits:
Object
  • Object
show all
Includes:
HasException
Defined in:
lib/seeing_is_believing/binary/add_annotations.rb

Constant Summary collapse

RESULT_PREFIX =
'# =>'
EXCEPTION_PREFIX =
'# ~>'
STDOUT_PREFIX =
'# >>'
STDERR_PREFIX =
'# !>'

Instance Attribute Summary collapse

Attributes included from HasException

#exception

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, options = {}) ⇒ AddAnnotations

Returns a new instance of AddAnnotations.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/seeing_is_believing/binary/add_annotations.rb', line 42

def initialize(body, options={})
  cleaned_body            = RemovePreviousAnnotations.call body
  self.options            = options
  self.body               = (xmpfilter_style ? body : cleaned_body)
  self.file_result        = SeeingIsBelieving.call body(),
                                                   filename:     (options[:as] || options[:filename]),
                                                   require:      options[:require],
                                                   load_path:    options[:load_path],
                                                   encoding:     options[:encoding],
                                                   stdin:        options[:stdin],
                                                   timeout:      options[:timeout],
                                                   debugger:     debugger
  self.alignment_strategy = options[:alignment_strategy].new cleaned_body, start_line, end_line
end

Instance Attribute Details

#file_resultObject

Returns the value of attribute file_result.



41
42
43
# File 'lib/seeing_is_believing/binary/add_annotations.rb', line 41

def file_result
  @file_result
end

Class Method Details

.method_from_options(*args) ⇒ Object



29
30
31
# File 'lib/seeing_is_believing/binary/add_annotations.rb', line 29

def self.method_from_options(*args)
  define_method(args.first) { options.fetch *args }
end

Instance Method Details

#callObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/seeing_is_believing/binary/add_annotations.rb', line 61

def call
  @printed_program ||= begin
    # can we put the call to chomp into the line_queue initialization code?
    line_queue.until { |line, line_number| SyntaxAnalyzer.begins_data_segment?(line.chomp) }
              .each  { |line, line_number| add_line line, line_number }
    add_stdout
    add_stderr
    add_exception
    add_remaining_lines
    if debugger.enabled?
      debugger.context("RESULT") { new_body }.to_s
    else
      new_body
    end
  end
end

#new_bodyObject



57
58
59
# File 'lib/seeing_is_believing/binary/add_annotations.rb', line 57

def new_body
  @new_body ||= ''
end