Class: RevertToGreenCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/revert_to_green_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(shell, view, meta_config_file, state_reader) ⇒ RevertToGreenCommand

Returns a new instance of RevertToGreenCommand.



3
4
5
6
7
8
# File 'lib/commands/revert_to_green_command.rb', line 3

def initialize shell, view, meta_config_file, state_reader
	@shell = shell
	@view = view
	@meta_config_file = meta_config_file
	@state_reader = state_reader
end

Instance Method Details

#accepts_shell_command?(command) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/commands/revert_to_green_command.rb', line 43

def accepts_shell_command? command
	command == 'revert-to-green'
end

#command_keyObject



39
40
41
# File 'lib/commands/revert_to_green_command.rb', line 39

def command_key
	'g'
end

#continue_test_loop?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/commands/revert_to_green_command.rb', line 47

def continue_test_loop?
	true
end

#executeObject



14
15
16
# File 'lib/commands/revert_to_green_command.rb', line 14

def execute
	revert_to_green
end

#execute_from_shell(params) ⇒ Object



10
11
12
# File 'lib/commands/revert_to_green_command.rb', line 10

def execute_from_shell params
	revert_to_green
end

#revert_to_greenObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/commands/revert_to_green_command.rb', line 18

def revert_to_green
	formatter = FilenameFormatter.new
	@state_reader.session_dir = formatter.session_dir @shell.newest_dir_entry(FilenameFormatter.codersdojo_workspace)
	@state_reader.goto_last_state
	state = @state_reader.read_previous_state if @state_reader.state_exist?
	while @state_reader.state_exist? and state.red?
		state = @state_reader.read_previous_state
	end
	if @state_reader.state_exist? and state.green?
		@view.show_revert_to_step @state_reader.next_step+1
		@shell.rm_r @meta_config_file.source_files
		state.files.each do |file|
			dest_file = Filename.new(file).extract_last_path_item.to_s
			@shell.write_file dest_file, @shell.read_file(file)
		end
	else
	  @view.show_no_green_state_to_revert_to
		@state_reader.goto_last_state
	end
end