Sha256: bced39905d335c1535095221b6c5d71f2fda93158ae86e6e3de07ea76b57b1cf

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

class Nib::Debug
  include Nib::Command

  def execute
    raise 'RUBY_DEBUG_PORT not specified. See "nib debug help"' unless port

    puts "Connecting to server via:\n> #{command}"

    super
  end

  private

  def command
    "byebug -R #{host}:#{port}"
  end

  def host
    return @host if @host

    @host = if ENV.key?('DOCKER_HOST_URL') && ENV['DOCKER_HOST_URL'] != ''
      URI.parse(ENV['DOCKER_HOST_URL']).host
    else
      `ip route | head -n 1`.chomp
    end

    @host = @host == '' ? '0.0.0.0' : @host
  end

  def compose_file
    @compose_file ||= File.read('docker-compose.yml')
  end

  def port
    regexp = /
      #{service}:     # start with the service key (web:)
      (?:.|\n)*?      # search through all characters including new lines
      RUBY_DEBUG_PORT # target the env var we defined
      \D*             # expect non-numeric characters (':', ': ', '=', '="')
      (?<port>\d+)    # capture numeric value of the port
    /x

    (compose_file.match(regexp) || {}).send(:[], :port)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nib-2.1.1 lib/nib/debug.rb