Class: SeeingIsBelieving

Inherits:
Object
  • Object
show all
Defined in:
lib/seeing_is_believing/wrap_expressions.rb,
lib/seeing_is_believing.rb,
lib/seeing_is_believing/code.rb,
lib/seeing_is_believing/safe.rb,
lib/seeing_is_believing/error.rb,
lib/seeing_is_believing/binary.rb,
lib/seeing_is_believing/result.rb,
lib/seeing_is_believing/version.rb,
lib/seeing_is_believing/debugger.rb,
lib/seeing_is_believing/backup_file.rb,
lib/seeing_is_believing/hash_struct.rb,
lib/seeing_is_believing/binary/config.rb,
lib/seeing_is_believing/binary/engine.rb,
lib/seeing_is_believing/hard_core_ensure.rb,
lib/seeing_is_believing/binary/align_file.rb,
lib/seeing_is_believing/binary/align_line.rb,
lib/seeing_is_believing/binary/align_chunk.rb,
lib/seeing_is_believing/event_stream/events.rb,
lib/seeing_is_believing/binary/comment_lines.rb,
lib/seeing_is_believing/binary/format_comment.rb,
lib/seeing_is_believing/event_stream/consumer.rb,
lib/seeing_is_believing/event_stream/producer.rb,
lib/seeing_is_believing/binary/data_structures.rb,
lib/seeing_is_believing/binary/interline_align.rb,
lib/seeing_is_believing/binary/rewrite_comments.rb,
lib/seeing_is_believing/binary/commentable_lines.rb,
lib/seeing_is_believing/evaluate_by_moving_files.rb,
lib/seeing_is_believing/binary/remove_annotations.rb,
lib/seeing_is_believing/binary/annotate_every_line.rb,
lib/seeing_is_believing/binary/annotate_end_of_file.rb,
lib/seeing_is_believing/event_stream/handlers/debug.rb,
lib/seeing_is_believing/binary/annotate_marked_lines.rb,
lib/seeing_is_believing/wrap_expressions_with_inspect.rb,
lib/seeing_is_believing/event_stream/handlers/update_result.rb,
lib/seeing_is_believing/event_stream/handlers/record_exit_events.rb,
lib/seeing_is_believing/event_stream/handlers/stream_json_events.rb

Overview

sigh need to find a way to join the annotators. They are sinful ugly, kinda hard to work with, and absurdly duplicated.

Defined Under Namespace

Modules: Binary, EventStream, Safe, WrapExpressionsWithInspect Classes: BackupFile, Code, Debugger, EvaluateByMovingFiles, HardCoreEnsure, HashStruct, Options, Result, TempFileAlreadyExists, WrapExpressions

Constant Summary collapse

SeeingIsBelievingError =

All our errors will inherit from this so that a user can catch any error generated by this lib

Class.new StandardError
NoMoreEvents =

EventStream

Class.new SeeingIsBelievingError
UnknownEvent =
Class.new SeeingIsBelievingError
VERSION =
'3.6.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program, options = {}) ⇒ SeeingIsBelieving

Returns a new instance of SeeingIsBelieving.



32
33
34
35
36
# File 'lib/seeing_is_believing.rb', line 32

def initialize(program, options={})
  @program = program
  @program += "\n" unless @program.end_with? "\n"
  @options = Options.new options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



31
32
33
# File 'lib/seeing_is_believing.rb', line 31

def options
  @options
end

Class Method Details

.call(*args) ⇒ Object



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

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/seeing_is_believing.rb', line 38

def call
  @memoized_result ||= Dir.mktmpdir("seeing_is_believing_temp_dir") { |dir|
    filename    = options.filename || File.join(dir, 'program.rb')
    new_program = options.rewrite_code.call @program

    options.debugger.context("REWRITTEN PROGRAM") { new_program }

    EvaluateByMovingFiles.call \
      new_program,
      filename,
      event_handler:     event_handler(options.debugger, options.event_handler),
      provided_input:    options.stdin,
      require_files:     options.require_files,
      load_path_dirs:    options.load_path_dirs,
      encoding:          options.encoding,
      timeout_seconds:   options.timeout_seconds,
      max_line_captures: options.max_line_captures,
      local_cwd:         options.local_cwd?

    options.event_handler
  }
end