Module: IRB::History

Defined in:
lib/irb/history/base.rb,
lib/irb/history/client.rb,
lib/irb/history/server.rb

Defined Under Namespace

Classes: Server

Constant Summary collapse

DEFAULT_HOST =
'127.0.0.1'
DEFAULT_PORT =
26501
DEFAULT_URI =
"druby://#{DEFAULT_HOST}:#{DEFAULT_PORT}"
DEFAULT_FILE =
'~/.irb_history'

Class Method Summary collapse

Class Method Details

.start_client(uri = DEFAULT_URI, lines_to_recall = 100) ⇒ Object

Reconfigures a running IRB session to use the given remote history service specified by uri, initially retrieving lines_to_recall lines of history.

Note: This method overrides gets in IRB::ReadlineInputMethod; it can’t be “stopped,” and you shouldn’t call it more than once.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/irb/history/client.rb', line 12

def self.start_client(uri = DEFAULT_URI, lines_to_recall = 100)
  require 'drb'
  
  DRb.start_service
  history = DRbObject.new nil, uri
  
  IRB::ReadlineInputMethod.instance_eval do
    alias_method :old_gets, :gets

    define_method :gets do
      returning old_gets do
        line = Readline::HISTORY[-1]
        history.remember line unless @eof rescue nil
      end
    end
  end

  Readline::HISTORY.push *history.recall(lines_to_recall)

  at_exit {history.unsubscribe_from Readline::HISTORY} if
    history.subscribe_to Readline::HISTORY
rescue   
end

.start_server(uri = DEFAULT_URI, store_path = DEFAULT_FILE) ⇒ Object

Starts a Server on the given uri and using the YAML history file specified by store_path. The Server object is instantiated, a DRb service is started on it, and the Server object is returned. The DRb service object is accessible via Server#service.



84
85
86
87
88
# File 'lib/irb/history/server.rb', line 84

def self.start_server(uri = DEFAULT_URI, store_path = DEFAULT_FILE)
  returning server = Server.new(store_path) do
    server.service = DRb.start_service uri, server
  end
end