Module: PrivateGemServer::Sanity

Defined in:
lib/private_gem_server/sanity.rb

Class Method Summary collapse

Class Method Details

.check!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/private_gem_server/sanity.rb', line 5

def self.check!

  # Make sure the git binary is installed
  fail! 'Please install git' if `which git` == ''

  # Make sure the gem executable is present
  fail! 'Cannot run `gem`' if `which gem` == ''

  # Make sure we have a valid config file
  begin
    config = YAML.load_file ENV['GEM_SOURCES']
  rescue
    fail! 'Please supply a path to your gem sources YAML file in the GEM_SOURCES environment variable.'
  end

  # Make sure config has a hash of gems
  fail! 'Config file includes no gems' unless Hash === config && Hash === config['gems'] && !config['gems'].empty?

  # Make sure we can write to our working dir
  store = ENV['GEM_STORE']
  fail! 'Please set GEM_STORE to a readable/writable directory' unless store &&
      File.directory?(store) &&
      File.readable?(store) &&
      File.writable?(store) &&
      File.executable?(store)

  # Make sure the log is writable
  log_path = ENV['GEM_SERVER_LOG']
  if log_path
    log_path = Pathname(log_path)
    if log_path.exist?
      fail! "Server log (#{log_path}) is not writable" unless log_path.writable?
    else
      log_path.parent.mkpath rescue fail! "Cannot create server log directory (#{log_path.parent})"
      log_path.write '' rescue fail! "Cannot create server log (#{log_path})"
    end
  end

end