Class: Console::Mux::Shell

Inherits:
Object show all
Defined in:
lib/console/mux/shell.rb

Overview

The interactive console is run within an instance of Shell. All instance methods are thus available as user commands.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(console) ⇒ Shell

Returns a new instance of Shell.



49
50
51
# File 'lib/console/mux/shell.rb', line 49

def initialize(console)
  @console = console
end

Instance Attribute Details

#consoleObject (readonly)

Returns the value of attribute console.



26
27
28
# File 'lib/console/mux/shell.rb', line 26

def console
  @console
end

Class Method Details

.delegate(obj_getter, method_syms) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/console/mux/shell.rb', line 29

def delegate(obj_getter, method_syms)
  method_syms.each do |sym|
    send(:define_method, sym) do |*args, &block|
      obj = send(obj_getter)
      obj.send(sym, *args, &block)
    end
  end
end

.delegate_ok(obj_getter, method_syms) ⇒ Object



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

def delegate_ok(obj_getter, method_syms)
  method_syms.each do |sym|
    send(:define_method, sym) do |*args, &block|
      obj = send(obj_getter)
      obj.send(sym, *args, &block)
      :ok
    end
  end
end

Instance Method Details

#commandsObject



53
54
55
# File 'lib/console/mux/shell.rb', line 53

def commands
  console.commands
end

#with_defaults(hash = {}) ⇒ Object

Yield the block with hash merged into the default options. The options are restored.



75
76
77
78
79
80
81
82
83
# File 'lib/console/mux/shell.rb', line 75

def with_defaults(hash={})
  orig_options = default_options
  set_default_options(default_options.merge(hash))
  begin
    yield
  ensure
    set_default_options(orig_options)
  end
end