Class: ProxyRb::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy_rb/console.rb,
lib/proxy_rb/console/help.rb

Overview

Consule

Defined Under Namespace

Modules: Help

Instance Method Summary collapse

Instance Method Details

#startObject

Start the proxy_rb console



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/proxy_rb/console.rb', line 12

def start
  # Start IRB with current context:
  # http://stackoverflow.com/questions/4189818/how-to-run-irb-start-in-context-of-current-class
  ARGV.clear
  IRB.setup nil

  IRB.conf[:IRB_NAME] = 'proxy_rb'

  IRB.conf[:PROMPT] = {}
  IRB.conf[:PROMPT][:PROXY_RB] = {
    PROMPT_I: '%N:%03n:%i> ',
    PROMPT_S: '%N:%03n:%i%l ',
    PROMPT_C: '%N:%03n:%i* ',
    RETURN: "# => %s\n"
  }
  IRB.conf[:PROMPT_MODE] = :PROXY_RB

  IRB.conf[:RC] = false

  require 'irb/completion'
  require 'irb/ext/save-history'
  IRB.conf[:READLINE] = true
  IRB.conf[:SAVE_HISTORY] = 1000
  IRB.conf[:HISTORY_FILE] = ProxyRb.config.console_history_file

  context = Class.new do
    include ProxyRb::Console::Help
    include ProxyRb::Api

    def inspect
      'nil'
    end
  end

  irb = IRB::Irb.new(IRB::WorkSpace.new(context.new))
  IRB.conf[:MAIN_CONTEXT] = irb.context

  trap('SIGINT') do
    irb.signal_handle
  end

  begin
    catch(:IRB_EXIT) do
      irb.eval_input
    end
  ensure
    IRB.irb_at_exit
  end
end