Module: GitPair::Commands

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

Instance Method Summary collapse

Instance Method Details

#add(name) ⇒ Object



12
13
14
15
# File 'lib/git-pair.rb', line 12

def add(name)
  @config_changed = true
  `git config --add git-pair.authors "#{name}"`
end

#config_change_made?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/git-pair.rb', line 27

def config_change_made?
  @config_changed
end

#remove(name) ⇒ Object



17
18
19
20
# File 'lib/git-pair.rb', line 17

def remove(name)
  @config_changed = true
  `git config --unset-all git-pair.authors "^#{name}$"`
end

#set_email_template(email) ⇒ Object



22
23
24
25
# File 'lib/git-pair.rb', line 22

def set_email_template(email)
  @config_changed = true
  `git config git-pair.email "#{email}"`
end

#switch(abbreviations) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/git-pair.rb', line 31

def switch(abbreviations)
  raise MissingConfigurationError, "Please add some authors first" if Helpers.author_names.empty?
  raise MissingConfigurationError, "Please set the email template first" if Helpers.email_template.empty?

  names = abbreviations.map { |abbrev|
    name = Helpers.author_name_from_abbreviation(abbrev)
    raise NoMatchingAuthorsError, "no authors matched #{abbrev}" if name.nil?
    name
  }

  sorted_names = names.uniq.sort_by { |name| name.split.last }
  `git config user.name "#{sorted_names.join(' + ')}"`
  initials = sorted_names.map { |name| name.split.map { |word| word[0].chr }.join.downcase }
  `git config user.email "#{Helpers.email(*initials)}"`
end