Module: Divvy::Verifiers

Defined in:
lib/divvy/verifiers.rb

Instance Method Summary collapse

Instance Method Details

#file_contains(path, text) ⇒ Object



8
9
10
# File 'lib/divvy/verifiers.rb', line 8

def file_contains(path, text)
  @commands << "grep '#{text}' #{path}"
end

#has_directory(dir) ⇒ Object

Tests that the directory dir exists.



13
14
15
# File 'lib/divvy/verifiers.rb', line 13

def has_directory(dir)
  @commands << "test -d #{dir}"
end

#has_executable(path) ⇒ Object

Checks if path is an executable script. This verifier is “smart” because if the path contains a forward slash ‘/’ then it assumes you’re checking an absolute path to an executable. If no ‘/’ is in the path, it assumes you’re checking for a global executable that would be available anywhere on the command line.



21
22
23
24
25
26
27
28
29
# File 'lib/divvy/verifiers.rb', line 21

def has_executable(path)
  # Be smart: If the path includes a forward slash, we're checking
  # an absolute path. Otherwise, we're checking a global executable
  if path.include?('/')
    @commands << "test -x #{path}"
  else
    @commands << "[ -n \"`echo \\`which #{path}\\``\" ]"
  end
end

#has_file(path) ⇒ Object

Checks to make sure path is a file on the remote server.



4
5
6
# File 'lib/divvy/verifiers.rb', line 4

def has_file(path)
  @commands << "test -f #{path}"
end

#has_gem(name, version = nil) ⇒ Object

Checks if a gem exists by calling “sudo gem list” and grepping against it.



47
48
49
50
# File 'lib/divvy/verifiers.rb', line 47

def has_gem(name, version=nil)
  version = version.nil? ? '' : version.gsub('.', '\.')
  @commands << "sudo gem list | grep -e '^#{name} (.*#{version}.*)$'"
end

#has_process(process) ⇒ Object

Checks to make sure process is a process running on the remote server.



33
34
35
# File 'lib/divvy/verifiers.rb', line 33

def has_process(process)
  @commands << "ps aux | grep '#{process}' | grep -v grep"
end

Checks that symlink is a symbolic link. If file is given, it checks that symlink points to file



54
55
56
57
58
59
60
# File 'lib/divvy/verifiers.rb', line 54

def has_symlink(symlink, file = nil)
  if file.nil?
    @commands << "test -L #{symlink}"
  else
    @commands << "test '#{file}' = `readlink #{symlink}`"
  end
end

#ruby_can_load(*files) ⇒ Object

Checks if ruby can require the files given. rubygems is always included first.



39
40
41
42
43
44
# File 'lib/divvy/verifiers.rb', line 39

def ruby_can_load(*files)
  # Always include rubygems first
  files = files.unshift('rubygems').collect { |x| "require '#{x}'" }
  
  @commands << "ruby -e \"#{files.join(';')}\""
end