Module: Git::Semaphore

Defined in:
lib/git/semaphore/api.rb,
lib/git/semaphore/banner.rb,
lib/git/semaphore/version.rb,
lib/git/semaphore/api_cache.rb,
lib/git/semaphore/copyright.rb,
lib/git/semaphore/api_enrich.rb,
lib/git/semaphore.rb

Defined Under Namespace

Classes: API, Project

Constant Summary collapse

<<-"EOS"
Usage: git-semaphore [options]

v#{Git::Semaphore::VERSION}

Options:
EOS
VERSION =
"2.0.0"
"git-semaphore v#{Git::Semaphore::VERSION} Copyright (c) 2012-2016 Peter Vandenberk"

Class Method Summary collapse

Class Method Details

.auth_tokenObject



69
70
71
# File 'lib/git/semaphore.rb', line 69

def self.auth_token
  git_auth_token || env_auth_token
end

.cache_dirObject



25
26
27
28
29
30
31
# File 'lib/git/semaphore.rb', line 25

def self.cache_dir
  @cache_dir ||= begin
    File.join(self.home_dir, '.git', 'semaphore').tap do |cache_dir|
      FileUtils.mkdir_p(cache_dir)
    end
  end
end

.cache_dir_for(identifier) ⇒ Object



33
34
35
36
37
# File 'lib/git/semaphore.rb', line 33

def self.cache_dir_for identifier
  File.join(self.cache_dir, identifier).tap do |cache_dir|
    FileUtils.mkdir_p(cache_dir)
  end
end

.empty_cache_dirObject



39
40
41
# File 'lib/git/semaphore.rb', line 39

def self.empty_cache_dir
  FileUtils.rm_r Dir.glob(File.join(self.cache_dir, '*'))
end

.env_auth_tokenObject



61
62
63
# File 'lib/git/semaphore.rb', line 61

def self.env_auth_token
  @env_auth_token ||= ENV['SEMAPHORE_AUTH_TOKEN']
end

.from_json_cache(path) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/git/semaphore.rb', line 43

def self.from_json_cache path
  if File.exists? path
    JSON.parse(File.read(path))
  else
    yield.tap do |content|
      File.open(path, 'w') { |file| file.write content.to_json }
    end
  end
end

.git_auth_tokenObject



65
66
67
# File 'lib/git/semaphore.rb', line 65

def self.git_auth_token
  git_repo && git_repo.config['semaphore.authtoken']
end

.git_repoObject



53
54
55
56
57
58
59
# File 'lib/git/semaphore.rb', line 53

def self.git_repo
  begin
    Rugged::Repository.new(Dir.pwd)
  rescue Rugged::RepositoryError
    nil
  end
end

.home_dirObject



19
20
21
22
23
# File 'lib/git/semaphore.rb', line 19

def self.home_dir
  @home_dir ||= begin
    ENV['HOME'] || File.expand_path("~#{Etc.getlogin}")
  end
end