Module: GitPair::Config

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

Instance Method Summary collapse

Instance Method Details

#add_author(author) ⇒ Object



36
37
38
39
40
# File 'lib/git-pair/config.rb', line 36

def add_author(author)
  unless Author.exists?(author)
    `git config --global --add git-pair.authors "#{author.name} <#{author.email}>"`
  end
end

#all_author_stringsObject



5
6
7
# File 'lib/git-pair/config.rb', line 5

def all_author_strings
  `git config --global --get-all git-pair.authors`.split("\n")
end

#avatar(authors) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/git-pair/config.rb', line 9

def avatar(authors)
  require 'digest/md5'
  require 'rmagick'
  require 'open-uri'

  imgs = []

  authors.each do |auth|
    hash = Digest::MD5.hexdigest(auth.email)
    image_src = "http://www.gravatar.com/avatar/#{hash}"

    imgs << Magick::Image.from_blob(open(image_src).read).first
  end

  imgs.first.crop!(0, 0, imgs.first.columns / 2, imgs.first.rows)

  midline = Magick::Image.new(2, imgs.last.columns, Magick::HatchFill.new('#800','#800'))

  imgs.last.composite!(imgs.first, Magick::WestGravity, Magick::AtopCompositeOp)
  imgs.last.composite!(midline, Magick::CenterGravity, Magick::AtopCompositeOp)


  filename = authors.map { |a| initials(a.name) }.join("+")

  imgs.last.write("#{filename}.jpg")
end

#current_authorObject



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

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

#current_emailObject



66
67
68
# File 'lib/git-pair/config.rb', line 66

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

#current_initialsObject



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

def current_initials
  current_author.split('+').map do |auth|
    initials(auth)
  end.join('+')
end

#default_emailObject



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

def default_email
  `git config --global --get user.email`.strip
end

#initials(name) ⇒ Object



70
71
72
# File 'lib/git-pair/config.rb', line 70

def initials(name)
  name.split.map { |word| word[0].chr }.join.downcase
end

#remove_author(name) ⇒ Object



42
43
44
45
# File 'lib/git-pair/config.rb', line 42

def remove_author(name)
  `git config --global --unset-all git-pair.authors "^#{name} <"`
  `git config --global --remove-section git-pair` if all_author_strings.empty?
end

#resetObject



54
55
56
# File 'lib/git-pair/config.rb', line 54

def reset
  `git config --remove-section user`
end

#switch(authors) ⇒ Object



47
48
49
50
51
52
# File 'lib/git-pair/config.rb', line 47

def switch(authors)
  authors.sort!

  `git config user.name "#{authors.map { |a| a.name }.join(' + ')}"`
  `git config user.email "#{Author.email(authors)}"`
end