Class: Brice::History

Inherits:
Object
  • Object
show all
Defined in:
lib/brice/history.rb

Overview

IRb history support.

Configure with config.history.opt = { ... }, where the following keys are recognized (see DEFAULTS):

:path

The path to your .irb_history file.

:size

The number of entries to keep in the history file.

:perms

The mode to open the history file with.

:uniq

Whether only unique history entries shall be saved. May also be :reverse to keep the most recent ones.

:merge

Whether to preserve, i.e. merge, the history across overlapping sessions.

Defined Under Namespace

Modules: Tee

Constant Summary collapse

DEFAULTS =
{
  path:   ENV['IRB_HISTORY_FILE'] || File.join(ENV.user_home, '.irb_history'),
  size:  (ENV['IRB_HISTORY_SIZE'] || 1000).to_i,
  perms: File::WRONLY | File::CREAT | File::TRUNC,
  uniq:  :reverse,
  merge: true
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt = {}, history = defined?(Readline::HISTORY) && Readline::HISTORY) ⇒ History

Returns a new instance of History.


57
58
59
60
61
62
63
64
65
66
# File 'lib/brice/history.rb', line 57

def initialize(opt = {}, history = defined?(Readline::HISTORY) && Readline::HISTORY)
  DEFAULTS.each { |key, val|
    instance_variable_set("@#{key}", Brice.opt(opt, key, val))
  }

  @path    = File.expand_path(@path)
  @reverse = @uniq.to_s == 'reverse'

  init_history(history) if history
end

Class Method Details

.init(opt = {}) ⇒ Object


53
54
55
# File 'lib/brice/history.rb', line 53

def self.init(opt = {})
  new(opt)
end