Module: GitPair::Config
Instance Method Summary collapse
- #add_author(author) ⇒ Object
- #all_author_strings ⇒ Object
- #avatar(authors) ⇒ Object
- #current_author ⇒ Object
- #current_email ⇒ Object
- #current_initials ⇒ Object
- #default_email ⇒ Object
- #initials(name) ⇒ Object
- #remove_author(name) ⇒ Object
- #reset ⇒ Object
- #switch(authors) ⇒ Object
Instance Method Details
#add_author(author) ⇒ Object
36 37 38 39 40 |
# File 'lib/git-pair/config.rb', line 36 def () unless Author.exists?() `git config --global --add git-pair.authors "#{.name} <#{.email}>"` end end |
#all_author_strings ⇒ Object
5 6 7 |
# File 'lib/git-pair/config.rb', line 5 def `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() require 'digest/md5' require 'rmagick' require 'open-uri' imgs = [] .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 = .map { |a| initials(a.name) }.join("+") imgs.last.write("#{filename}.jpg") end |
#current_author ⇒ Object
62 63 64 |
# File 'lib/git-pair/config.rb', line 62 def `git config --get user.name`.strip end |
#current_email ⇒ Object
66 67 68 |
# File 'lib/git-pair/config.rb', line 66 def current_email `git config --get user.email`.strip end |
#current_initials ⇒ Object
74 75 76 77 78 |
# File 'lib/git-pair/config.rb', line 74 def current_initials .split('+').map do |auth| initials(auth) end.join('+') end |
#default_email ⇒ Object
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 (name) `git config --global --unset-all git-pair.authors "^#{name} <"` `git config --global --remove-section git-pair` if .empty? end |
#reset ⇒ Object
54 55 56 |
# File 'lib/git-pair/config.rb', line 54 def reset `git config --remove-section user` end |