Sha256: 15c76471788f3d1b3091086e3ace232cbf136d77e37d6ddbc3769b30f237bc94

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

module ArubaDoubles
  class History

    include Enumerable

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

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

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

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

    # @return [String] inspection of the entries
    def to_s
      to_a.inspect
    end

    # Return entries just like running `history` in your shell.
    # @return [String] pretty representation of the entries
    def to_pretty
      to_a.each_with_index.map { |e,i| "%5d  %s" % [i+1, e.shelljoin] }.join("\n")
    end

  private

    def entries
      @store.transaction(readonly=true) do
        @store[:history] || []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aruba-doubles-1.2.1 lib/aruba-doubles/history.rb