Class: EnvUtil::Debugger

Inherits:
Object
  • Object
show all
Defined in:
lib/envutil.rb

Constant Summary collapse

PRECOMMAND =

sudo -n: –non-interactive

(%[sudo -n] if /darwin/ =~ RUBY_PLATFORM)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Debugger

Returns a new instance of Debugger.



91
92
93
94
# File 'lib/envutil.rb', line 91

def initialize(name, &block)
  @name = name
  instance_eval(&block)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



85
86
87
# File 'lib/envutil.rb', line 85

def name
  @name
end

Class Method Details

.register(name, &block) ⇒ Object



87
88
89
# File 'lib/envutil.rb', line 87

def self.register(name, &block)
  @list << new(name, &block)
end

.searchObject



143
144
145
# File 'lib/envutil.rb', line 143

def self.search
  @debugger ||= @list.find(&:usable?)
end

Instance Method Details

#dump(pid, timeout: 60, reprieve: timeout&.div(4)) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/envutil.rb', line 100

def dump(pid, timeout: 60, reprieve: timeout&.div(4))
  dpid = start(pid, *command_file(File.join(__dir__, "dump.#{name}")), out: :err)
rescue Errno::ENOENT
  return
else
  return unless dpid
  [[timeout, :TERM], [reprieve, :KILL]].find do |t, sig|
    begin
      return EnvUtil.timeout(t) {Process.wait(dpid)}
    rescue Timeout::Error
      Process.kill(sig, dpid)
    end
  end
  true
end

#spawn(*args, **opts) ⇒ Object



119
120
121
# File 'lib/envutil.rb', line 119

def spawn(*args, **opts)
  super(*PRECOMMAND, *args, **opts)
end

#start(pid, *args) ⇒ Object



98
# File 'lib/envutil.rb', line 98

def start(pid, *args) end

#usable?Boolean

Returns:

  • (Boolean)


96
# File 'lib/envutil.rb', line 96

def usable?; false; end