Module: PairUp

Defined in:
lib/pair-up.rb,
lib/pair-up/ui.rb,
lib/pair-up/participant.rb

Defined Under Namespace

Classes: Participant, UI

Constant Summary collapse

VERSION =
'1.0.4'

Class Method Summary collapse

Class Method Details

.author_commandObject



44
45
46
47
48
49
50
# File 'lib/pair-up.rb', line 44

def self.author_command
  if PairUp.pairing?
    "export GIT_AUTHOR_NAME='#{PairUp.git_author_name}' GIT_AUTHOR_EMAIL='#{PairUp.git_author_email}' GIT_COMMITTER_NAME='#{PairUp.git_committer_name}' GIT_COMMITTER_EMAIL='#{PairUp.git_committer_email}'"
  else
    "unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL"
  end
end

.current_pairObject



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

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

.current_pair=(pairs) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pair-up.rb', line 62

def self.current_pair=(pairs)
  config[:current_pair] = []
  pairs.each do |participant|
    if PairUp::Participant.find(participant)
      config[:current_pair] << participant
    else
      if PairUp::UI.prompt_for_pair(participant)
        config[:current_pair] << participant
      end
    end
  end
  write_file
end

.expire_command(time) ⇒ Object



29
30
31
# File 'lib/pair-up.rb', line 29

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

.export(pairs) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pair-up.rb', line 17

def self.export(pairs)
  PairUp.current_pair = pairs

  if PairUp.mac?
    `launchctl setenv GIT_AUTHOR_NAME '#{PairUp.git_author_name}' GIT_AUTHOR_EMAIL '#{PairUp.git_author_email}'`
    `launchctl setenv GIT_COMMITTER_NAME '#{PairUp.git_committer_name}' GIT_COMMITTER_EMAIL '#{PairUp.git_committer_email}'`
  end

  write_export_file
  print_info
end

.git_author_emailObject



81
82
83
84
# File 'lib/pair-up.rb', line 81

def self.git_author_email
  dev = PairUp::Participant.find(current_pair[0])
  dev["email"]
end

.git_author_nameObject



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

def self.git_author_name
  dev = PairUp::Participant.find(current_pair[0])
  dev["name"]
end

.git_committer_emailObject



91
92
93
94
# File 'lib/pair-up.rb', line 91

def self.git_committer_email
  dev = PairUp::Participant.find(current_pair[1])
  dev["email"]
end

.git_committer_nameObject



86
87
88
89
# File 'lib/pair-up.rb', line 86

def self.git_committer_name
  dev = PairUp::Participant.find(current_pair[1])
  dev["name"]
end


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

def self.print_info
  if PairUp.pairing? && STDOUT.tty?
    PairUp::UI.highline.say("Author: #{PairUp.git_author_name} <#{PairUp.git_author_email}>, Committer: #{PairUp.git_committer_name} <#{PairUp.git_committer_email}>")
  end
end


100
101
102
# File 'lib/pair-up.rb', line 100

def self.print_setup_path
  puts setup_path
end

.setupObject



104
105
106
# File 'lib/pair-up.rb', line 104

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

.setup_pathObject



96
97
98
# File 'lib/pair-up.rb', line 96

def self.setup_path
  File.join(File.dirname(__FILE__), 'pair-up', 'pair-up.sh')
end

.switchObject



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

def self.switch
  if not current_pair.empty?
    PairUp.export current_pair.reverse
  end
end

.unpairObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/pair-up.rb', line 33

def self.unpair
  PairUp.current_pair = []

  if PairUp.mac?
    `launchctl unsetenv GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL`
    `launchctl unsetenv GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL`
  end

  write_export_file
end

.write_fileObject



108
109
110
111
112
# File 'lib/pair-up.rb', line 108

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