Sha256: 00d8448f8d5651383fec1cb6cc3f522ac320f2dbe6930edf511d21f14873ba6f

Contents?: true

Size: 803 Bytes

Versions: 4

Compression:

Stored size: 803 Bytes

Contents

module Jets::Git
  class User
    extend Memoist
    include GitCli

    def first_name
      name.split(" ").first if name # name can be nil
    end

    def name
      saved[:git_user] || git_config["user.name"]
    end

    def saved
      return {} unless File.exist?(".jets/gitinfo.yml")
      data = YAML.load_file(".jets/gitinfo.yml")
      ActiveSupport::HashWithIndifferentAccess.new(data)
    end

    def git_config
      return {} if ENV["JETS_GIT_DISABLED"]

      return {} unless git?
      list = git("config --list")
      lines = list.split("\n")
      # Other values in the git config are not needed.
      # And can cause .to_h to bomb and throw an error.
      lines.select! { |l| l =~ /^user\./ }
      lines.map { |l| l.split("=") }.to_h
    end
    memoize :git_config
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/git/user.rb
jets-6.0.4 lib/jets/git/user.rb
jets-6.0.3 lib/jets/git/user.rb
jets-6.0.2 lib/jets/git/user.rb