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_error, #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

Create a new shell.

Parameters:

  • config (Hash) (defaults to: {})

    The config of the shell.

Options Hash (config):

  • :config (String) — default: '~/.rib/config.rb'

    The path to Rib config file.

  • :name (String) — default: 'rib'

    The name of the shell. Used for Rib application.

  • :result_prompt (String) — default: '=> '
  • :prompt (String) — default: '>> '
  • :binding (Binding, Object) — default: new_private_binding

    The context of the shell. Could be an Object.

  • :exit (Array<String>) — default: [nil]

    The keywords to exit the shell. ‘nil` means EOF (ctrl+d).

  • :line (Fixnum) — default: 1

    The beginning of line number.

  • :history_file (String) — default: '~/.rib/config/history.rb'

    (Only if History plugin is used) The path to history file.

  • :history_size (Fixnum) — default: 500

    (Only if History plugin is used) Maximum numbers of history.

  • :color (Hash<Class, Symbol>) — default: ...

    (Only if Color plugin is used) Data type colors mapping.

  • :autoindent_spaces (String) — default: ' '

    (Only if Autoindent plugin is used) The indented string.



38
39
40
41
42
43
44
45
# File 'lib/rib/shell.rb', line 38

def initialize(config={})
  config[:binding] ||= new_private_binding
  self.config = {:result_prompt => '=> ',
                 :prompt        => '>> ',
                 :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



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rib/shell.rb', line 48

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)


61
62
63
# File 'lib/rib/shell.rb', line 61

def running?
  !!@running
end