module Hitch

Constants

VERSION

Public Class Methods

author_command() click to toggle source
# 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_pair() click to toggle source
# File lib/hitch.rb, line 49
def self.current_pair
  config[:current_pair] ||= []
end
current_pair=(pairs) click to toggle source
# 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) click to toggle source
# File lib/hitch.rb, line 23
def self.expire_command(time)
  %Q(sleep #{to_seconds(time)} && #{Hitch.bin_path} --unhitch&)
end
export(pairs) click to toggle source
# File lib/hitch.rb, line 17
def self.export(pairs)
  Hitch.current_pair = pairs
  write_export_file
  print_info
end
git_author_email() click to toggle source
# File lib/hitch.rb, line 77
def self.git_author_email
  "#{group_prefix}+#{current_pair.sort.join('+')}@#{group_domain}"
end
git_author_name() click to toggle source
# 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_domain() click to toggle source
# File lib/hitch.rb, line 85
def self.group_domain
  group_email.split('@').last
end
group_email() click to toggle source
# File lib/hitch.rb, line 40
def self.group_email
  config[:group_email] ||= Hitch::UI.prompt_for_group_email
end
group_email=(email) click to toggle source
# File lib/hitch.rb, line 44
def self.group_email=(email)
  config[:group_email] = email
  write_file
end
group_prefix() click to toggle source
# File lib/hitch.rb, line 81
def self.group_prefix
  group_email.split('@').first
end
print_info() click to toggle source
print_setup_path() click to toggle source
setup() click to toggle source
# File lib/hitch.rb, line 97
def self.setup
  Hitch::UI.highline.say(File.read(setup_path))
end
setup_path() click to toggle source
# File lib/hitch.rb, line 89
def self.setup_path
  File.join(File.dirname(__FILE__), 'hitch', 'hitch.sh')
end
unhitch() click to toggle source
# File lib/hitch.rb, line 27
def self.unhitch
  Hitch.current_pair = []
  write_export_file
end
write_file() click to toggle source
# 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

Private Class Methods

bin_path() click to toggle source
# File lib/hitch.rb, line 129
def self.bin_path
  %x[which hitch].chomp
end
config() click to toggle source
# File lib/hitch.rb, line 109
def self.config
  @config ||= get_config
end
get_config() click to toggle source
# File lib/hitch.rb, line 113
def self.get_config
  if File.exists?(hitchrc)
    yamlized = YAML::load_file(hitchrc)
    return yamlized if yamlized.kind_of?(Hash)
  end
  return {}
end
hitch_export_authors() click to toggle source
# File lib/hitch.rb, line 125
def self.hitch_export_authors
  File.expand_path('~/.hitch_export_authors')
end
hitchrc() click to toggle source
# File lib/hitch.rb, line 121
def self.hitchrc
  File.expand_path('~/.hitchrc')
end
pairing?() click to toggle source
# File lib/hitch.rb, line 133
def self.pairing?
  current_pair.any?
end
to_seconds(value) click to toggle source
# File lib/hitch.rb, line 137
def self.to_seconds(value)
  value = value.to_s.gsub(/[^\d]/, '').to_i
  unless value.zero?
    value * 60 * 60
  else
    raise StandardError
  end
end
write_export_file() click to toggle source
# File lib/hitch.rb, line 146
def self.write_export_file
  File.open(hitch_export_authors, 'w'){|f| f.write(author_command) }
end