Module: RedShift::Shell

Defined in:
lib/redshift/mixins/shell.rb

Overview

extend a World instance with this (or include in a World subclass)

Instance Method Summary collapse

Instance Method Details

#after_shellObject

Override to complete some action after leaving shell.



38
39
# File 'lib/redshift/mixins/shell.rb', line 38

def after_shell
end

#before_shellObject

Override to complete some action before dropping into shell.



34
35
# File 'lib/redshift/mixins/shell.rb', line 34

def before_shell
end

#recoverable_error(e, msg = "Error", bt = []) ⇒ Object

Typically, call this in a rescue clause, if you to let the user examine state and possibly continue:

rescue ... => e
  require 'redshift/mixins/irb-shell'
  world.extend RedShift::IRBShell
  world.recoverable_error e, "Assertion failure", e.backtrace


49
50
51
52
53
54
# File 'lib/redshift/mixins/shell.rb', line 49

def recoverable_error e, msg = "Error", bt = []
  puts "#{msg} at time #{clock}"
  puts "From " + bt[0..2].join("\n     ") unless bt.empty
  puts "     ..." if bt.length > 3
  shell.run
end

#runObject



18
19
20
21
# File 'lib/redshift/mixins/shell.rb', line 18

def run(*)
  shell.install_interrupt_handler
  super
end

#shellObject



14
15
16
# File 'lib/redshift/mixins/shell.rb', line 14

def shell
  @shell ||= IRBShell.new(binding, self)
end

#stepObject



23
24
25
26
27
28
29
30
31
# File 'lib/redshift/mixins/shell.rb', line 23

def step(*)
  super do
    yield self if block_given?
    if shell.handle_interrupt {before_shell}
      after_shell
      return
    end
  end
end