Sha256: 01fbdf8b4178f73dbbe891b1d7d944ebf644fff50ded4618b936a72eb3c878c4

Contents?: true

Size: 970 Bytes

Versions: 6

Compression:

Stored size: 970 Bytes

Contents

require 'yaml'

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
    if ENV.key?('DOCKER_HOST_URL') && ENV['DOCKER_HOST_URL'] != ''
      URI.parse(ENV['DOCKER_HOST_URL']).host
    else
      `ip route | awk 'NR==1 {print $3}'`.chomp
    end
  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

6 entries across 6 versions & 1 rubygems

Version Path
nib-1.4.0 lib/nib/debug.rb
nib-1.3.0 lib/nib/debug.rb
nib-1.2.2 lib/nib/debug.rb
nib-1.2.1 lib/nib/debug.rb
nib-1.2.0 lib/nib/debug.rb
nib-1.1.0 lib/nib/debug.rb