Class: Giticious::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/giticious/check.rb

Class Method Summary collapse

Class Method Details

.git_installed?Boolean

Returns:



22
23
24
# File 'lib/giticious/check.rb', line 22

def self.git_installed?
  `which git 2>/dev/null` and $?.success?
end

.repository_dir_exists?Boolean

Returns:



26
27
28
# File 'lib/giticious/check.rb', line 26

def self.repository_dir_exists?
  Dir.exists?("#{Dir.home}/repositories")
end

.runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/giticious/check.rb', line 7

def self.run
  if self.git_installed? == false
    raise RuntimeError, "Git is not installed"
  end

  if self.repository_dir_exists? == false
    raise RuntimeError, "Repository dir not found! Please run the init command"
  end

  if self.ssh_alive? == false
    raise RuntimeError, "SSH service not listening on Port 22! Please enable it and use public key auth"
  end
end

.ssh_alive?Boolean

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/giticious/check.rb', line 30

def self.ssh_alive?
  begin
    Timeout::timeout(5) do
      begin
        s = TCPSocket.new("127.0.0.1", 22)
        s.close
        return true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
        return false
      end
    end
  rescue Timeout::Error
  end

  false
end