Top Level Namespace
Defined Under Namespace
Classes: HostList
Constant Summary collapse
- CONFIG_FILE =
File.join Etc.getpwuid.dir, ".eymigrate.yml"
Instance Method Summary collapse
- #add_host ⇒ Object
- #config_file? ⇒ Boolean
- #delete_host(host) ⇒ Object
- #delete_menu ⇒ Object
- #display_hosts ⇒ Object
- #edit_host(host) ⇒ Object
- #edit_menu ⇒ Object
- #formatted_entry(host, ip) ⇒ Object
- #help_text(exit_code = 0) ⇒ Object
- #list_mappings ⇒ Object
-
#main_menu ⇒ Object
Menus.
Instance Method Details
#add_host ⇒ Object
46 47 48 49 50 |
# File 'bin/eymigrate', line 46 def add_host host = ask("Please enter the hostname (eg. www.mycorp.com): ") ip = ask("Please enter the ip address (eg. 127.0.0.1): ") HostList.add(host, ip) end |
#config_file? ⇒ Boolean
23 24 25 |
# File 'bin/eymigrate', line 23 def config_file? File.exists? CONFIG_FILE end |
#delete_host(host) ⇒ Object
57 58 59 |
# File 'bin/eymigrate', line 57 def delete_host(host) HostList.remove(host) end |
#delete_menu ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'bin/eymigrate', line 117 def exit = false begin choose do || .select_by = :index .prompt = "Choose a hostname delete:" say "--------------------------------------------------------" say "- Existing entries -" say "--------------------------------------------------------" if HostList.has_entries? HostList.each do |host, ip| .choice(formatted_entry(host, ip)) { |c| delete_host(c.match(/^(\w|\.)+/)[0]) } end else say "No IP mappings in place" end say "--------------------------------------------------------" .choice(:back) { exit = true } end end while exit == false end |
#display_hosts ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'bin/eymigrate', line 32 def display_hosts say "--------------------------------------------------------" say "- Existing entries -" say "--------------------------------------------------------" if HostList.has_entries? HostList.each do |host, ip| say formatted_entry(host, ip) end else say "No IP mappings in place" end say "--------------------------------------------------------" end |
#edit_host(host) ⇒ Object
52 53 54 55 |
# File 'bin/eymigrate', line 52 def edit_host(host) ip = ask("Enter the new IP (eg. 127.0.0.1): ") HostList.update(host, ip) end |
#edit_menu ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'bin/eymigrate', line 94 def exit = false begin choose do || .select_by = :index .prompt = "Choose a hostname to edit:" say "--------------------------------------------------------" say "- Existing entries -" say "--------------------------------------------------------" if HostList.has_entries? HostList.each do |host, ip| .choice(formatted_entry(host, ip)) { |c| edit_host(c.match(/^(\w|\.)+/)[0]) } end else say "No IP mappings in place" end say "--------------------------------------------------------" .choice(:back) { exit = true } end end while exit == false end |
#formatted_entry(host, ip) ⇒ Object
27 28 29 30 |
# File 'bin/eymigrate', line 27 def formatted_entry(host, ip) # puts "#{domain}: #{ip}" sprintf("%-20s -> #{ip}", host) end |
#help_text(exit_code = 0) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'bin/eymigrate', line 13 def help_text(exit_code = 0) script_name = File.basename $0 puts """USAGE: #{script_name} on #{script_name} off #{script_name} list #{script_name} configure """ exit(exit_code) end |
#list_mappings ⇒ Object
147 148 149 150 151 |
# File 'bin/eymigrate', line 147 def list_mappings HostList.each do |host, ip| puts formatted_entry(host, ip) end end |
#main_menu ⇒ Object
Menus
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'bin/eymigrate', line 67 def if config_file? end exit = false begin display_hosts say "* Depending on your system these these rules may not *" say "* persist across reboots, run `eymigrate on` to re-add *" say '* the rules and always check you are accessing the *' say "* servers you think you are. *" say "--------------------------------------------------------" choose do || .select_by = :index .prompt = "Where would you like to go today?" .choice("Add hostname") { add_host } .choice("Edit hostname") { } .choice("Delete hostname") { } .choice(:quit) { exit = true } end end while exit == false end |