Class: IRB::JobManager
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/irb/ext/multi-irb.rb |
Class Method Summary
-
.new ⇒ JobManager
constructor
Creates a new
JobManager
object.
Instance Attribute Summary
-
#current_job
rw
The active irb session.
Instance Method Summary
-
#delete(key)
Deletes the job at the given
key
. -
#insert(irb)
Add the given #irb session to the jobs Array.
-
#inspect
Outputs a list of jobs, see the irb command
irb_jobs
, orjobs
. -
#irb(key)
Returns the irb session for the given
key
object, see #search for more information. -
#kill(*keys)
Terminates the irb sessions specified by the given
keys
. -
#main_irb
Returns the top level irb session.
-
#main_thread
Returns the top level thread.
-
#n_jobs
The total number of irb sessions, used to set
irb_name
of the current Context. -
#search(key)
Returns the associated job for the given
key
. -
#switch(key)
Changes the current active irb session to the given
key
in the jobs Array. -
#thread(key)
Returns the thread for the given
key
object, see #search for more information.
Constructor Details
.new ⇒ JobManager
Creates a new JobManager
object
# File 'lib/irb/ext/multi-irb.rb', line 19
def initialize @jobs = [] @current_job = nil end
Instance Attribute Details
#current_job (rw)
The active irb session
# File 'lib/irb/ext/multi-irb.rb', line 25
attr_accessor :current_job
Instance Method Details
#delete(key)
Deletes the job at the given key
.
# File 'lib/irb/ext/multi-irb.rb', line 123
def delete(key) case key when Integer IRB.fail NoSuchJob, key unless @jobs[key] @jobs[key] = nil else catch(:EXISTS) do @jobs.each_index do |i| if @jobs[i] and (@jobs[i][0] == key || @jobs[i][1] == key || @jobs[i][1].context.main.equal?(key)) @jobs[i] = nil throw :EXISTS end end IRB.fail NoSuchJob, key end end until assoc = @jobs.pop; end unless @jobs.empty? @jobs.push assoc end
#insert(irb)
Add the given #irb session to the jobs Array.
#inspect
Outputs a list of jobs, see the irb command irb_jobs
, or jobs
.
# File 'lib/irb/ext/multi-irb.rb', line 147
def inspect ary = [] @jobs.each_index do |i| th, irb = @jobs[i] next if th.nil? if th.alive? if th.stop? t_status = "stop" else t_status = "running" end else t_status = "exited" end ary.push format("#%d->%s on %s (%s: %s)", i, irb.context.irb_name, irb.context.main, th, t_status) end ary.join("\n") end
#irb(key)
Returns the irb session for the given key
object, see #search for more information.
# File 'lib/irb/ext/multi-irb.rb', line 42
def irb(key) _, irb = search(key) irb end
#kill(*keys)
Terminates the irb sessions specified by the given keys
.
Raises an IrbAlreadyDead exception if one of the given keys
is already terminated.
See Thread#exit
for more information.
#main_irb
Returns the top level irb session.
# File 'lib/irb/ext/multi-irb.rb', line 53
def main_irb @jobs[0][1] end
#main_thread
Returns the top level thread.
# File 'lib/irb/ext/multi-irb.rb', line 48
def main_thread @jobs[0][0] end
#n_jobs
The total number of irb sessions, used to set irb_name
of the current Context.
# File 'lib/irb/ext/multi-irb.rb', line 29
def n_jobs @jobs.size end
#search(key)
Returns the associated job for the given key
.
If given an Integer, it will return the key
index for the jobs Array.
When an instance of Irb is given, it will return the irb session associated with key
.
If given an instance of Thread, it will return the associated thread key
using Object#===
on the jobs Array.
Otherwise returns the irb session with the same top-level binding as the given key
.
Raises a NoSuchJob exception if no job can be found with the given key
.
#switch(key)
Changes the current active irb session to the given key
in the jobs Array.
Raises an IrbAlreadyDead exception if the given key
is no longer alive.
If the given irb session is already active, an IrbSwitchedToCurrentThread exception is raised.
#thread(key)
Returns the thread for the given key
object, see #search for more information.
# File 'lib/irb/ext/multi-irb.rb', line 35
def thread(key) th, = search(key) th end