Class: ArubaDoubles::History

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aruba-doubles/history.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ History

Returns a new instance of History.



6
7
8
# File 'lib/aruba-doubles/history.rb', line 6

def initialize(filename)
  @store = PStore.new(filename)
end

Instance Method Details

#<<(args) ⇒ Object



10
11
12
13
14
15
# File 'lib/aruba-doubles/history.rb', line 10

def <<(args)
  @store.transaction do
    @store[:history] ||= []
    @store[:history] << args
  end
end

#clearObject



17
18
19
20
21
# File 'lib/aruba-doubles/history.rb', line 17

def clear
  @store.transaction do
    @store[:history] = []
  end
end

#eachObject



23
24
25
# File 'lib/aruba-doubles/history.rb', line 23

def each
  entries.each { |e| yield(e) }
end

#to_prettyString

Return entries just like running ‘history` in your shell.

Returns:

  • (String)

    pretty representation of the entries



34
35
36
# File 'lib/aruba-doubles/history.rb', line 34

def to_pretty
  to_a.each_with_index.map { |e,i| "%5d  %s" % [i+1, e.shelljoin] }.join("\n")
end

#to_sString

Returns inspection of the entries.

Returns:

  • (String)

    inspection of the entries



28
29
30
# File 'lib/aruba-doubles/history.rb', line 28

def to_s
  to_a.inspect
end