Class: Jets::Git::User

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
GitCli
Defined in:
lib/jets/git/user.rb

Instance Method Summary collapse

Methods included from GitCli

#git, #git?, #git_commits?, #git_folder?, #git_installed?

Instance Method Details

#first_nameObject



6
7
8
# File 'lib/jets/git/user.rb', line 6

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

#git_configObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jets/git/user.rb', line 20

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

#nameObject



10
11
12
# File 'lib/jets/git/user.rb', line 10

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

#savedObject



14
15
16
17
18
# File 'lib/jets/git/user.rb', line 14

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