Class: DeleteTool

Inherits:
Object
  • Object
show all
Defined in:
lib/adaptrex/deletetool.rb

Instance Method Summary collapse

Constructor Details

#initialize(appConfig) ⇒ DeleteTool

Returns a new instance of DeleteTool.



20
21
22
23
# File 'lib/adaptrex/deletetool.rb', line 20

def initialize(appConfig)
	@appConfig = appConfig
	promptForDeletion
end

Instance Method Details

#promptForApplicationObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/adaptrex/deletetool.rb', line 73

def promptForApplication
	print "Which page do you want to delete? : "
	selection = STDIN.gets.chomp
	len = @appPages.length
	erm = ("Invalid selection. Enter a number from 1 to " + len.to_s).err
	if not selection.numeric?
		puts erm
		return promptForApplication
	end
	selection = Integer(selection)
	if not (1..len).include?selection
		puts erm
		return promptForApplication
	end
	return @appInfoList[selection - 1]
end

#promptForDeletionObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/adaptrex/deletetool.rb', line 25

def promptForDeletion
	@appInfoList = []
	@appPages = @appConfig.pages

	if @appPages.length < 1
		puts "There are no pages to delete.".warn
		return
	end
	
	puts "Page List".blue

	index = 0
	@appPages.sort.map.each {|appPath,appValue|
		appName = appValue.split(",")[0]
		@appInfoList.push({
			"name"	=> appName,
			"path"	=> appPath,
			"text"  => appName + " (" + appPath + ")"
		})
		i = index + 1
		if i < 10 then pad = " " else pad = "" end
		puts "  [" + pad + i.to_s + "] " + appName + " (" + appPath + ")"
		index += 1
	}
	puts ""
	
	appToDelete = promptForApplication
	puts(("Are you sure you want to delete " + appToDelete["text"] + ")?").warn)
	print "Type 'DELETE' to confirm: ".indent
	confirm = STDIN.gets.chomp

	if confirm == "DELETE"
		FileUtils.rm_rf(appToDelete["path"])
		@appConfig.pages.delete(appToDelete["path"])
		@appConfig.write
		puts((appToDelete["text"] + " has been deleted\n\n").success)
	else
		puts "Your app (page) was not deleted".warn
	end

	print "Do you want to delete another page? [n]: "
	doAnother = STDIN.gets.chomp.downcase
	if (doAnother == "y" or doAnother == "yes")
		puts ""
		return promptForDeletion
	end
end