Class: Meshchat::Ui::Command::Bind
- Defined in:
- lib/meshchat/ui/command/bind.rb
Constant Summary
Constants inherited from Base
Meshchat::Ui::Command::Base::ADD, Meshchat::Ui::Command::Base::ALL_CHAT_LOCK, Meshchat::Ui::Command::Base::BIND, Meshchat::Ui::Command::Base::CHAT, Meshchat::Ui::Command::Base::CONFIG, Meshchat::Ui::Command::Base::DISPLAY, Meshchat::Ui::Command::Base::EMOTE, Meshchat::Ui::Command::Base::EXIT, Meshchat::Ui::Command::Base::EXPORT, Meshchat::Ui::Command::Base::HELP, Meshchat::Ui::Command::Base::IDENTITY, Meshchat::Ui::Command::Base::IMPORT, Meshchat::Ui::Command::Base::IRB, Meshchat::Ui::Command::Base::OFFLINE, Meshchat::Ui::Command::Base::ONLINE, Meshchat::Ui::Command::Base::PING, Meshchat::Ui::Command::Base::PING_ALL, Meshchat::Ui::Command::Base::QUIT, Meshchat::Ui::Command::Base::REMOVE, Meshchat::Ui::Command::Base::RM, Meshchat::Ui::Command::Base::ROLL, Meshchat::Ui::Command::Base::SEND_DISCONNECT, Meshchat::Ui::Command::Base::SERVER, Meshchat::Ui::Command::Base::SERVERS, Meshchat::Ui::Command::Base::SET, Meshchat::Ui::Command::Base::SHARE, Meshchat::Ui::Command::Base::WHISPER_LOCK, Meshchat::Ui::Command::Base::WHO
Instance Attribute Summary
Attributes inherited from Base
#_input, #_input_factory, #_message_dispatcher, #_message_factory
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Meshchat::Ui::Command::Base
Class Method Details
.description ⇒ Object
9 10 11 |
# File 'lib/meshchat/ui/command/bind.rb', line 9 def self.description 'helper for choosing what ip address to use for yourself' end |
Instance Method Details
#handle ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/meshchat/ui/command/bind.rb', line 13 def handle = ip_addresses option_numbers = [] Display.success 'Choose an ip:' .each_with_index do |ip, index| Display.info "#{index}: #{ip}" option_numbers << index end selected = gets if option_numbers.include?(selected.to_i) Display.success Settings.set('ip', with: [selected.to_i]) else Display.alert 'Invalid selection' handle # repeat end end |
#ip_addresses ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/meshchat/ui/command/bind.rb', line 32 def ip_addresses local = Socket.getifaddrs.map { |i| i.addr.ip_address if i.addr.ipv4? }.compact # get public begin remote_ip = open('http://whatismyip.akamai.com').read local << remote_ip rescue => e Display.fatal e. Display.alert 'public ip lookup failed' end local end |