Module: WifiWand::Commands::Registry
- Included in:
- WifiWand::CommandLineInterface, WifiWand::CommandLineParser
- Defined in:
- lib/wifi_wand/commands/registry.rb
Instance Method Summary collapse
-
#attempt_command_action(command_string, &error_handler_block) ⇒ Object
Look up the command name and, if found, run it.
- #commands ⇒ Object
- #find_command(command_string) ⇒ Object
- #find_command_action(command_string) ⇒ Object
- #resolve_command(command_string) ⇒ Object
Instance Method Details
#attempt_command_action(command_string, &error_handler_block) ⇒ Object
Look up the command name and, if found, run it. If not, execute the passed block.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/wifi_wand/commands/registry.rb', line 78 def attempt_command_action(command_string, *, &error_handler_block) action = find_command_action(command_string) if action action.call(*) else error_handler_block.call nil end end |
#commands ⇒ Object
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 |
# File 'lib/wifi_wand/commands/registry.rb', line 33 def commands @commands ||= [ WifiWand::Commands::AvailNets.new, WifiWand::Commands::Ci.new, WifiWand::Commands::Connect.new, WifiWand::Commands::Cycle.new, WifiWand::Commands::Disconnect.new, WifiWand::Commands::Forget.new, WifiWand::Commands::Help.new, WifiWand::Commands::Info.new, WifiWand::Commands::Log.new, WifiWand::Commands::Nameservers.new, WifiWand::Commands::NetworkName.new, WifiWand::Commands::Off.new, WifiWand::Commands::On.new, WifiWand::Commands::Password.new, WifiWand::Commands::PublicIp.new, WifiWand::Commands::PrefNets.new, WifiWand::Commands::Quit.new, WifiWand::Commands::Qr.new, WifiWand::Commands::RandomMac.new, WifiWand::Commands::Ropen.new, WifiWand::Commands::Shell.new, WifiWand::Commands::Status.new, WifiWand::Commands::Till.new, WifiWand::Commands::Url.new, WifiWand::Commands::WifiOn.new, ] end |
#find_command(command_string) ⇒ Object
63 64 65 |
# File 'lib/wifi_wand/commands/registry.rb', line 63 def find_command(command_string) commands.detect { |command| command.aliases.include?(command_string) } end |
#find_command_action(command_string) ⇒ Object
72 73 74 75 |
# File 'lib/wifi_wand/commands/registry.rb', line 72 def find_command_action(command_string) command = resolve_command(command_string) command&.method(:call) end |
#resolve_command(command_string) ⇒ Object
67 68 69 70 |
# File 'lib/wifi_wand/commands/registry.rb', line 67 def resolve_command(command_string) command = find_command(command_string) command&.bind(self) end |