Class: Rib::Shell

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/rib/shell.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from API

#after_loop, #before_loop, #bound_object, #eval_binding, #eval_input, #format_error, #format_result, #get_input, #handle_interrupt, #in_loop, #line, #loop_eval, #loop_once, #name, #print_eval_error, #print_result, #prompt, #result_prompt

Constructor Details

#initialize(config = {}) ⇒ Shell

Returns a new instance of Shell.



14
15
16
17
18
19
20
21
22
# File 'lib/rib/shell.rb', line 14

def initialize(config={})
  self.config = {
    :result_prompt => '=> '           ,
    :prompt        => '>> '           ,
    :binding       => TOPLEVEL_BINDING,
    :exit          => [nil]           ,
    :line          => 1               }.merge(config)
  @running = false
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



13
14
15
# File 'lib/rib/shell.rb', line 13

def config
  @config
end

Class Method Details

.use(mod) ⇒ Object



9
10
11
# File 'lib/rib/shell.rb', line 9

def self.use mod
  include mod
end

Instance Method Details

#loopObject

Loops shell until user exits



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rib/shell.rb', line 25

def loop
  before_loop
  @running = true
  in_loop
  self
rescue Exception => e
  Rib.warn("Error while running loop:\n  #{format_error(e)}")
  raise
ensure
  @running = false
  after_loop
end

#running?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rib/shell.rb', line 38

def running?
  !!@running
end