Module: Rib::MultilineHistoryFile

Extended by:
Plugin
Defined in:
lib/rib/more/multiline_history_file.rb

Instance Attribute Summary

Attributes included from Plugin

#disabled

Instance Method Summary collapse

Methods included from Plugin

const_missing, disable, disabled?, enable, enabled?, extended

Instance Method Details

#before_loopObject

————— Rib API —————



10
11
12
13
14
# File 'lib/rib/more/multiline_history_file.rb', line 10

def before_loop
  return super if MultilineHistoryFile.disabled?
  multiline_history_file_token
  super
end

#read_historyObject

————— Plugin API —————



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rib/more/multiline_history_file.rb', line 18

def read_history
  return super if MultilineHistoryFile.disabled?
  buffer = []
  File.exist?(history_file_path) && history.empty? &&
    IO.readlines(history_file_path).each{ |line|
      if line.end_with?(
           "#{config[:multiline_history_file_token]}\n")
        buffer << line[0...
                       -multiline_history_file_token.size-1] + "\n"
      else
        history << (buffer.join + line).chomp
        buffer = []
      end
    }
end

#write_historyObject



34
35
36
37
38
39
40
41
# File 'lib/rib/more/multiline_history_file.rb', line 34

def write_history
  return super if MultilineHistoryFile.disabled?
  # TODO: hisotroy.map is MRI 1.9+
  config[:history] = history.to_a.map{ |line|
    line.gsub("\n", "#{config[:multiline_history_file_token]}\n")
  }
  super
end