Class: StateRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/record/state_recorder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell, session_id_generator, meta_config_file) ⇒ StateRecorder

Returns a new instance of StateRecorder.



9
10
11
12
13
14
# File 'lib/record/state_recorder.rb', line 9

def initialize shell, session_id_generator, meta_config_file
	@shell = shell
	@session_id_generator = session_id_generator
	@meta_config_file = meta_config_file
	@filename_formatter = FilenameFormatter.new
end

Instance Attribute Details

#session_idObject

Returns the value of attribute session_id.



7
8
9
# File 'lib/record/state_recorder.rb', line 7

def session_id
  @session_id
end

#stepObject

Returns the value of attribute step.



7
8
9
# File 'lib/record/state_recorder.rb', line 7

def step
  @step
end

Instance Method Details

#init_sessionObject



16
17
18
19
20
21
22
23
# File 'lib/record/state_recorder.rb', line 16

def init_session
  @step = 0
  @session_id = @session_id_generator.generate_id
session_dir = @filename_formatter.session_dir @session_id
  @shell.mkdir_p session_dir
session_dir
  @shell.cp MetaConfigFile::PROPERTY_FILENAME, session_dir
end

#record_state(files, process) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/record/state_recorder.rb', line 25

def record_state files, process
	result = TextConverter.new.remove_escape_sequences process.output
	return_code_evaluator = ReturnCodeEvaluator.new @meta_config_file.success_detection	
   return_code = return_code_evaluator.return_code(process)
   state_dir = @filename_formatter.state_dir @session_id, @step
   now = Time.new
   date = now.strftime "%Y-%m-%d"
   time = now.strftime "%H:%M:%S"
   @shell.mkdir state_dir
   @shell.cp_r files, state_dir
   write_result_file state_dir, result
   write_info_file(state_dir, {:return_code => return_code, :date => "'#{date}'", :time => "'#{time}'", :step => @step})
	@step += 1
end

#write_info_file(state_dir, properties) ⇒ Object



44
45
46
47
# File 'lib/record/state_recorder.rb', line 44

def write_info_file state_dir, properties
	content = properties.collect{|key, value| "#{key}: #{value}"}.join "\n"
   @shell.write_file @filename_formatter.info_file(state_dir), content
end

#write_result_file(state_dir, result) ⇒ Object



40
41
42
# File 'lib/record/state_recorder.rb', line 40

def write_result_file state_dir, result
@shell.write_file @filename_formatter.result_file(state_dir), result
end