Class: ArubaDoubles::History
- Inherits:
-
Object
- Object
- ArubaDoubles::History
- Includes:
- Enumerable
- Defined in:
- lib/aruba-doubles/history.rb
Instance Method Summary collapse
- #<<(args) ⇒ Object
- #clear ⇒ Object
- #each ⇒ Object
-
#initialize(filename) ⇒ History
constructor
A new instance of History.
-
#to_pretty ⇒ String
Return entries just like running ‘history` in your shell.
-
#to_s ⇒ String
Inspection of the entries.
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 |
#clear ⇒ Object
17 18 19 20 21 |
# File 'lib/aruba-doubles/history.rb', line 17 def clear @store.transaction do @store[:history] = [] end end |
#each ⇒ Object
23 24 25 |
# File 'lib/aruba-doubles/history.rb', line 23 def each entries.each { |e| yield(e) } end |
#to_pretty ⇒ String
Return entries just like running ‘history` in your shell.
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_s ⇒ String
Returns inspection of the entries.
28 29 30 |
# File 'lib/aruba-doubles/history.rb', line 28 def to_s to_a.inspect end |