Module: Archer

Defined in:
lib/archer.rb,
lib/archer/irb.rb,
lib/archer/engine.rb,
lib/archer/history.rb,
lib/archer/version.rb,
lib/generators/archer/install_generator.rb

Defined Under Namespace

Modules: Generators, Irb Classes: Engine, History

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.clearObject



59
60
61
62
63
64
65
# File 'lib/archer.rb', line 59

def clear
  quietly do
    Archer::History.where(user: user).delete_all
  end
  history_object.clear if history_object
  true
end

.saveObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/archer.rb', line 46

def save
  return false unless history_object

  quietly do
    history = Archer::History.where(user: user).first_or_initialize
    history.commands = history_object.to_a.last(limit).join("\n")
    history.save!
  end
rescue ActiveRecord::StatementInvalid
  warn "[archer] Unable to save history"
  false
end

.startObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/archer.rb', line 22

def start
  if !history_object
    warn "[archer] Skipping history"
    return
  end

  history = nil
  begin
    quietly do
      history = Archer::History.find_by(user: user)
    end
  rescue ActiveRecord::StatementInvalid
    warn "[archer] Create table to enable history"
  end

  if history
    commands = history.commands.split("\n")
    history_object.clear
    history_object.push(*commands)
  end

  IRB.conf[:AT_EXIT].push(proc { Archer.save if Archer.save_session })
end