Class: SeeingIsBelieving::EvaluateByMovingFiles

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, user_program, rewritten_program, options = {}) ⇒ EvaluateByMovingFiles

Returns a new instance of EvaluateByMovingFiles.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 66

def initialize(file_path, user_program, rewritten_program, options={})
  options = options.dup
  self.user_program      = user_program
  self.rewritten_program = rewritten_program
  self.encoding          = options.delete(:encoding)           || "u"
  self.timeout_seconds   = options.delete(:timeout_seconds)    || 0 # 0 is the new infinity
  self.provided_input    = options.delete(:provided_input)     || String.new
  self.event_handler     = options.delete(:event_handler)      || raise(ArgumentError, "must provide an :event_handler")
  self.load_path_flags   = (options.delete(:load_path_dirs)    || []).flat_map { |dir| ['-I', dir] }
  self.require_flags     = (options.delete(:require_files)     || ['seeing_is_believing/the_matrix']).map { |filename| ['-r', filename] }.flatten
  self.max_line_captures = (options.delete(:max_line_captures) || Float::INFINITY) # (optimization: child stops producing results at this number, even though it might make more sense for the consumer to stop emitting them)
  self.local_cwd         = options.delete(:local_cwd)          || false
  self.file_path         = file_path
  self.file_directory    = File.dirname file_path
  file_name              = File.basename file_path
  self.relative_filename = local_cwd ? file_name : file_path
  self.backup_path       = File.join file_directory, "seeing_is_believing_backup.#{file_name}"

  options.any? && raise(ArgumentError, "Unknown options: #{options.inspect}")
end

Instance Attribute Details

#backup_pathObject

Returns the value of attribute backup_path.



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

def backup_path
  @backup_path
end

#debuggerObject

Returns the value of attribute debugger.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def debugger
  @debugger
end

#encodingObject

Returns the value of attribute encoding.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def encoding
  @encoding
end

#event_handlerObject

Returns the value of attribute event_handler.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def event_handler
  @event_handler
end

#file_directoryObject

Returns the value of attribute file_directory.



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

def file_directory
  @file_directory
end

#file_pathObject

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

#load_path_flagsObject

Returns the value of attribute load_path_flags.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def load_path_flags
  @load_path_flags
end

#local_cwdObject

Returns the value of attribute local_cwd.



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

def local_cwd
  @local_cwd
end

#max_line_capturesObject

Returns the value of attribute max_line_captures.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def max_line_captures
  @max_line_captures
end

#provided_inputObject

Returns the value of attribute provided_input.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def provided_input
  @provided_input
end

#relative_filenameObject

Returns the value of attribute relative_filename.



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

def relative_filename
  @relative_filename
end

#require_flagsObject

Returns the value of attribute require_flags.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def require_flags
  @require_flags
end

#rewritten_programObject

Returns the value of attribute rewritten_program.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def rewritten_program
  @rewritten_program
end

#timeout_secondsObject

Returns the value of attribute timeout_seconds.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def timeout_seconds
  @timeout_seconds
end

#user_programObject

Returns the value of attribute user_program.



62
63
64
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 62

def user_program
  @user_program
end

Class Method Details

.call(*args) ⇒ Object



58
59
60
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 58

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

Instance Method Details

#callObject



87
88
89
90
91
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 87

def call
  SwapFiles.call file_path, backup_path, user_program, rewritten_program do |swap_files|
    evaluate_file swap_files
  end
end