Class: SeeingIsBelieving::EvaluateByMovingFiles
- Inherits:
-
Object
- Object
- SeeingIsBelieving::EvaluateByMovingFiles
- Defined in:
- lib/seeing_is_believing/evaluate_by_moving_files.rb
Instance Attribute Summary collapse
-
#debugger ⇒ Object
Returns the value of attribute debugger.
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#input_stream ⇒ Object
Returns the value of attribute input_stream.
-
#load_path_flags ⇒ Object
Returns the value of attribute load_path_flags.
-
#matrix_filename ⇒ Object
Returns the value of attribute matrix_filename.
-
#program ⇒ Object
Returns the value of attribute program.
-
#require_flags ⇒ Object
Returns the value of attribute require_flags.
-
#ruby_executable ⇒ Object
Returns the value of attribute ruby_executable.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #call ⇒ Object
- #file_directory ⇒ Object
-
#initialize(program, filename, options = {}) ⇒ EvaluateByMovingFiles
constructor
A new instance of EvaluateByMovingFiles.
- #temp_filename ⇒ Object
Constructor Details
#initialize(program, filename, options = {}) ⇒ EvaluateByMovingFiles
Returns a new instance of EvaluateByMovingFiles.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def initialize(program, filename, ={}) self.program = program self.filename = filename self.input_stream = .fetch :input_stream, StringIO.new('') self.matrix_filename = [:matrix_filename] || 'seeing_is_believing/the_matrix' self.require_flags = .fetch(:require, []).map { |filename| ['-r', filename] }.flatten self.load_path_flags = .fetch(:load_path, []).map { |dir| ['-I', dir] }.flatten self.encoding = .fetch :encoding, nil self.timeout = [:timeout] self.ruby_executable = .fetch :ruby_executable, 'ruby' self.debugger = .fetch :debugger, Debugger.new(stream: nil) end |
Instance Attribute Details
#debugger ⇒ Object
Returns the value of attribute debugger.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def debugger @debugger end |
#encoding ⇒ Object
Returns the value of attribute encoding.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def encoding @encoding end |
#filename ⇒ Object
Returns the value of attribute filename.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def filename @filename end |
#input_stream ⇒ Object
Returns the value of attribute input_stream.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def input_stream @input_stream end |
#load_path_flags ⇒ Object
Returns the value of attribute load_path_flags.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def load_path_flags @load_path_flags end |
#matrix_filename ⇒ Object
Returns the value of attribute matrix_filename.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def matrix_filename @matrix_filename end |
#program ⇒ Object
Returns the value of attribute program.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def program @program end |
#require_flags ⇒ Object
Returns the value of attribute require_flags.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def require_flags @require_flags end |
#ruby_executable ⇒ Object
Returns the value of attribute ruby_executable.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def ruby_executable @ruby_executable end |
#timeout ⇒ Object
Returns the value of attribute timeout.
26 27 28 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 26 def timeout @timeout end |
Instance Method Details
#call ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 41 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 => error error = wrap_error error if error_implies_bug_in_sib? error raise error end }, ensure: -> { set_back_to_initial_conditions } end |
#file_directory ⇒ Object
62 63 64 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62 def file_directory File.dirname filename end |
#temp_filename ⇒ Object
66 67 68 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 66 def temp_filename File.join file_directory, "seeing_is_believing_backup.#{File.basename filename}" end |