Sha256: 3623e73a9f1439369ce081374b184003243c95c57972d11f3d4e81c9ccbfb8c7

Contents?: true

Size: 816 Bytes

Versions: 7

Compression:

Stored size: 816 Bytes

Contents

# frozen_string_literal: true

require 'git'
require 'open3'

module Treeish
  class Base
    attr_reader :git

    def initialize(git: nil)
      @git = git || Git.open(Dir.pwd)
    end

    def recents
      get_treeishes(recents_command) do |line, names|
        next if reject_strategy(line, names)
        names << {
          value: value_strategy(line, names),
          name: name_strategy(line, names)
        }
      end
    end

    private

    def recents_command; end
    def reject_strategy(line, names); end
    def value_strategy(line, names); end
    def name_strategy(line, names); end

    def get_treeishes(cmd)
      names = []
      _stdin, stdout, _stderr, _wait_thr = Open3.popen3(cmd)
      stdout.each(sep="\n") do |line|
        yield(line, names)
      end
      names
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gnav-0.6.4 lib/treeish/base.rb
gnav-0.6.3 lib/treeish/base.rb
gnav-0.6.2 lib/treeish/base.rb
gnav-0.6.1 lib/treeish/base.rb
gnav-0.6.0 lib/treeish/base.rb
gnav-0.5.2 lib/treeish/base.rb
gnav-0.5.0 lib/treeish/base.rb