Module: GitPair::Helpers

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/git-pair.rb

Instance Method Summary collapse

Instance Method Details

#abort(error_message, extra = "") ⇒ Object



101
102
103
# File 'lib/git-pair.rb', line 101

def abort(error_message, extra = "")
  super "#{$red}#{$reverse} Error: #{error_message} #{$reset}\n" + extra
end

#author_name_from_abbreviation(abbrev) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/git-pair.rb', line 84

def author_name_from_abbreviation(abbrev)
  # initials
  author_names.each do |name|
    return name if abbrev.downcase == name.split.map { |word| word[0].chr }.join.downcase
  end

  # start of a name
  author_names.each do |name|
    return name if name.gsub(" ", "") =~ /^#{abbrev}/i
  end

  # includes the letters in order
  author_names.detect do |name|
    name =~ /#{abbrev.split("").join(".*")}/i
  end
end

#author_namesObject



62
63
64
65
# File 'lib/git-pair.rb', line 62

def author_names
  names = `git config --get-all git-pair.authors`.split("\n")
  names.uniq.sort_by { |name| name.split.last }
end

#current_authorObject



76
77
78
# File 'lib/git-pair.rb', line 76

def current_author
  `git config --get user.name`.strip
end

#current_emailObject



80
81
82
# File 'lib/git-pair.rb', line 80

def current_email
  `git config --get user.email`.strip
end

#display_string_for_configObject



52
53
54
55
# File 'lib/git-pair.rb', line 52

def display_string_for_config
  "#{$bold}  Email template: #{$reset}" + email("[aa]", "[bb]") + "\n" +
  "#{$bold}     Author list: #{$reset}" + author_names.join("\n                  ")
end

#display_string_for_current_infoObject



57
58
59
60
# File 'lib/git-pair.rb', line 57

def display_string_for_current_info
  "#{$bold}  Current author: #{$reset}" + current_author + "\n" +
  "#{$bold}   Current email: #{$reset}" + current_email + "\n "
end

#email(*initials_list) ⇒ Object



67
68
69
70
# File 'lib/git-pair.rb', line 67

def email(*initials_list)
  initials_string = initials_list.map { |initials| "+#{initials}" }.join
  email_template.sub("@", "#{initials_string}@")
end

#email_templateObject



72
73
74
# File 'lib/git-pair.rb', line 72

def email_template
  `git config --get git-pair.email`.strip
end