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.
-
#event_handler ⇒ Object
Returns the value of attribute event_handler.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#load_path_flags ⇒ Object
Returns the value of attribute load_path_flags.
-
#max_line_captures ⇒ Object
Returns the value of attribute max_line_captures.
-
#program ⇒ Object
Returns the value of attribute program.
-
#provided_input ⇒ Object
Returns the value of attribute provided_input.
-
#require_flags ⇒ Object
Returns the value of attribute require_flags.
-
#timeout_seconds ⇒ Object
Returns the value of attribute timeout_seconds.
Class Method Summary collapse
Instance Method Summary collapse
- #backup_filename ⇒ Object
- #call ⇒ Object
- #file_directory ⇒ Object
-
#initialize(program, filename, options = {}) ⇒ EvaluateByMovingFiles
constructor
A new instance of EvaluateByMovingFiles.
Constructor Details
#initialize(program, filename, options = {}) ⇒ EvaluateByMovingFiles
Returns a new instance of EvaluateByMovingFiles.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 30 def initialize(program, filename, ={}) = .dup self.program = program self.filename = filename self.encoding = .delete(:encoding) self.timeout_seconds = .delete(:timeout_seconds) || 0 # 0 is the new infinity self.provided_input = .delete(:provided_input) || String.new self.event_handler = .delete(:event_handler) || raise(ArgumentError, "must provide an :event_handler") self.load_path_flags = (.delete(:load_path_dirs) || []).map { |dir| ['-I', dir] }.flatten self.require_flags = (.delete(:require_files) || ['seeing_is_believing/the_matrix']).map { |filename| ['-r', filename] }.flatten self.max_line_captures = (.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) .any? && raise(ArgumentError, "Unknown options: #{.inspect}") end |
Instance Attribute Details
#debugger ⇒ Object
Returns the value of attribute debugger.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def debugger @debugger end |
#encoding ⇒ Object
Returns the value of attribute encoding.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def encoding @encoding end |
#event_handler ⇒ Object
Returns the value of attribute event_handler.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def event_handler @event_handler end |
#filename ⇒ Object
Returns the value of attribute filename.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def filename @filename end |
#load_path_flags ⇒ Object
Returns the value of attribute load_path_flags.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def load_path_flags @load_path_flags end |
#max_line_captures ⇒ Object
Returns the value of attribute max_line_captures.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def max_line_captures @max_line_captures end |
#program ⇒ Object
Returns the value of attribute program.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def program @program end |
#provided_input ⇒ Object
Returns the value of attribute provided_input.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def provided_input @provided_input end |
#require_flags ⇒ Object
Returns the value of attribute require_flags.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def require_flags @require_flags end |
#timeout_seconds ⇒ Object
Returns the value of attribute timeout_seconds.
28 29 30 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 28 def timeout_seconds @timeout_seconds end |
Class Method Details
.call(*args) ⇒ Object
24 25 26 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 24 def self.call(*args) new(*args).call end |
Instance Method Details
#backup_filename ⇒ Object
61 62 63 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 61 def backup_filename File.join file_directory, "seeing_is_believing_backup.#{File.basename filename}" end |
#call ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 44 def call HardCoreEnsure.call \ code: -> { we_will_not_overwrite_existing_backup_file! backup_existing_file write_program_to_file evaluate_file }, ensure: -> { set_back_to_initial_conditions } end |
#file_directory ⇒ Object
57 58 59 |
# File 'lib/seeing_is_believing/evaluate_by_moving_files.rb', line 57 def file_directory File.dirname filename end |