module PortMap::Utilities
Constants
- BASH_CMD_STRING
- BASH_SHELL
- STARTING_PORT_NUMBER
- ZSH_CMD_STRING
- ZSH_SHELL
Public Class Methods
apply_open_port_option(port, cmd)
click to toggle source
# File lib/port_map/utilities.rb, line 22 def self.apply_open_port_option(port, cmd) port_option_flag = '--port' if cmd.sub!(/-p\s+(\d+)/, '') port_option_flag = '-p' elsif cmd.sub!(/--port\s+(\d+)/, '') port_option_flag = '--port' end [cmd.strip, port_option_flag, port].join(' ') end
next_empty_port()
click to toggle source
# File lib/port_map/utilities.rb, line 34 def self.next_empty_port highest_port = PortMap::Mappings.all.map do |port_map| port_map[:locations].detect { |location| location[:name] == '/' }[:proxy_pass].split(':').last.to_i end.sort.reverse.first || STARTING_PORT_NUMBER - 1 highest_port += 1 highest_port += 1 while port_taken?(highest_port) highest_port end
port_taken?(port)
click to toggle source
# File lib/port_map/utilities.rb, line 45 def self.port_taken?(port) system("lsof -i:#{port}", out: '/dev/null') end
shell_cmd_wrapper(cmd)
click to toggle source
# File lib/port_map/utilities.rb, line 11 def self.shell_cmd_wrapper(cmd) case ENV.fetch('SHELL') when ZSH_SHELL ZSH_CMD_STRING % { path: ENV.fetch('PATH'), cmd: cmd } when BASH_SHELL BASH_CMD_STRING % { path: ENV.fetch('PATH'), cmd: cmd } else cmd end end