Module: Git::Semaphore

Defined in:
lib/git/semaphore.rb,
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

Defined Under Namespace

Classes: API, App

Constant Summary collapse

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

v#{Git::Semaphore::VERSION}

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

Class Method Summary collapse

Class Method Details

.auth_tokenObject



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

def self.auth_token
  git_auth_token || env_auth_token
end

.cache_dirObject



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

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



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

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



32
33
34
# File 'lib/git/semaphore.rb', line 32

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

.env_auth_tokenObject



54
55
56
# File 'lib/git/semaphore.rb', line 54

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

.from_json_cache(path) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/git/semaphore.rb', line 36

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



58
59
60
# File 'lib/git/semaphore.rb', line 58

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

.git_repoObject



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

def self.git_repo
  @git_repo ||= begin
    Grit::Repo.new(Dir.pwd)
  rescue Grit::InvalidGitRepositoryError
    nil
  end
end

.home_dirObject



12
13
14
15
16
# File 'lib/git/semaphore.rb', line 12

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