Class: SeeingIsBelieving::EvaluateByMovingFiles

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program, filename, options = {}) ⇒ EvaluateByMovingFiles

Returns a new instance of EvaluateByMovingFiles.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 27

def initialize(program, filename, options={})
  self.program         = program
  self.filename        = filename
  self.error_stream    = options.fetch :error_stream, $stderr # hmm, not really liking the global here
  self.input_stream    = options.fetch :input_stream, StringIO.new('')
  self.matrix_filename = options[:matrix_filename] || 'seeing_is_believing/the_matrix'
  self.require_flags   = options.fetch(:require, []).map { |filename| ['-r', filename] }.flatten
  self.load_path_flags = options.fetch(:load_path, []).map { |dir| ['-I', dir] }.flatten
  self.encoding        = options.fetch :encoding, nil
  self.timeout         = options[:timeout]
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def encoding
  @encoding
end

#error_streamObject

Returns the value of attribute error_stream.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def error_stream
  @error_stream
end

#filenameObject

Returns the value of attribute filename.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def filename
  @filename
end

#input_streamObject

Returns the value of attribute input_stream.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def input_stream
  @input_stream
end

#load_path_flagsObject

Returns the value of attribute load_path_flags.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def load_path_flags
  @load_path_flags
end

#matrix_filenameObject

Returns the value of attribute matrix_filename.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def matrix_filename
  @matrix_filename
end

#programObject

Returns the value of attribute program.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def program
  @program
end

#require_flagsObject

Returns the value of attribute require_flags.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def require_flags
  @require_flags
end

#timeoutObject

Returns the value of attribute timeout.



25
26
27
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 25

def timeout
  @timeout
end

Instance Method Details

#callObject



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

def call
  @result ||= HardCoreEnsure.call \
    code: -> {
      we_will_not_overwrite_existing_tempfile!
      move_file_to_tempfile
      write_program_to_file
      begin
        evaluate_file
        deserialize_result.tap { |result| fail if result.bug_in_sib? }
      # Okay, really, I should wrap this in another exception and raise it on up,
      # but for now, I'm feeling a little lazy and am not going to do it
      rescue Exception
        notify_user_of_error if error_implies_bug_in_sib? $!
        raise $!
      end
    },
    ensure: -> {
      set_back_to_initial_conditions
    }
end

#file_directoryObject



60
61
62
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 60

def file_directory
  File.dirname filename
end

#temp_filenameObject



64
65
66
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 64

def temp_filename
  File.join file_directory, "seeing_is_believing_backup.#{File.basename filename}"
end