Module: Hitch

Defined in:
lib/hitch.rb,
lib/hitch/ui.rb,
lib/hitch/author.rb

Defined Under Namespace

Classes: Author, UI

Constant Summary collapse

VERSION =
'1.1.0'

Class Method Summary collapse

Class Method Details

.author_commandObject



32
33
34
35
36
37
38
# File 'lib/hitch.rb', line 32

def self.author_command
  if Hitch.pairing?
    %Q{export GIT_AUTHOR_NAME="#{Hitch.git_author_name}" GIT_AUTHOR_EMAIL="#{Hitch.git_author_email}"}
  else
    "unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL"
  end
end

.current_pairObject



49
50
51
# File 'lib/hitch.rb', line 49

def self.current_pair
  config[:current_pair] ||= []
end

.current_pair=(pairs) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hitch.rb', line 53

def self.current_pair=(pairs)
  config[:current_pair] = []
  pairs.each do |author|
    if Hitch::Author.find(author)
      config[:current_pair] << author
    else
      if Hitch::UI.prompt_for_pair(author)
        config[:current_pair] << author
      end
    end
  end
  write_file
end

.expire_command(time) ⇒ Object



23
24
25
# File 'lib/hitch.rb', line 23

def self.expire_command(time)
  %Q(sleep #{to_seconds(time)} && #{Hitch.bin_path} --unhitch&)
end

.export(pairs) ⇒ Object



17
18
19
20
21
# File 'lib/hitch.rb', line 17

def self.export(pairs)
  Hitch.current_pair = pairs
  write_export_file
  print_info
end

.git_author_emailObject



77
78
79
# File 'lib/hitch.rb', line 77

def self.git_author_email
  "#{group_prefix}+#{current_pair.sort.join('+')}@#{group_domain}"
end

.git_author_nameObject



67
68
69
70
71
72
73
74
75
# File 'lib/hitch.rb', line 67

def self.git_author_name
  devs = current_pair.sort.map {|pair| Hitch::Author.find(pair)}
  case devs.length
  when 1, 2
    devs.join(" and ")
  else
    "#{devs[0...-1].join(', ')}, and #{devs[-1]}"
  end
end

.group_domainObject



85
86
87
# File 'lib/hitch.rb', line 85

def self.group_domain
  group_email.split('@').last
end

.group_emailObject



40
41
42
# File 'lib/hitch.rb', line 40

def self.group_email
  config[:group_email] ||= Hitch::UI.prompt_for_group_email
end

.group_email=(email) ⇒ Object



44
45
46
47
# File 'lib/hitch.rb', line 44

def self.group_email=(email)
  config[:group_email] = email
  write_file
end

.group_prefixObject



81
82
83
# File 'lib/hitch.rb', line 81

def self.group_prefix
  group_email.split('@').first
end


11
12
13
14
15
# File 'lib/hitch.rb', line 11

def self.print_info
  if Hitch.pairing? && STDOUT.tty?
    Hitch::UI.highline.say("#{Hitch.git_author_name} <#{Hitch.git_author_email}>")
  end
end


93
94
95
# File 'lib/hitch.rb', line 93

def self.print_setup_path
  puts setup_path
end

.setupObject



97
98
99
# File 'lib/hitch.rb', line 97

def self.setup
  Hitch::UI.highline.say(File.read(setup_path))
end

.setup_pathObject



89
90
91
# File 'lib/hitch.rb', line 89

def self.setup_path
  File.join(File.dirname(__FILE__), 'hitch', 'hitch.sh')
end

.unhitchObject



27
28
29
30
# File 'lib/hitch.rb', line 27

def self.unhitch
  Hitch.current_pair = []
  write_export_file
end

.write_fileObject



101
102
103
104
105
# File 'lib/hitch.rb', line 101

def self.write_file
  File.open(hitchrc, File::CREAT|File::TRUNC|File::RDWR, 0644) do |out|
    YAML.dump(config, out)
  end
end