Module: Capistrano::Baptize::Plugins::Base

Defined in:
lib/baptize/plugins/base.rb

Instance Method Summary collapse

Instance Method Details

#fail_verification(message = "Assertion failed") ⇒ Object



5
6
7
# File 'lib/baptize/plugins/base.rb', line 5

def fail_verification(message = "Assertion failed")
  raise VerificationFailure, message
end

#file_contains(path, text, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/baptize/plugins/base.rb', line 24

def file_contains(path, text, options = {})
  options = {:mode => :text}.merge(options)
  if options[:mode] == :text
    command = Array(text.strip.split("\n")).flatten.map {|line| "grep --fixed-strings #{line.shellescape} #{path.shellescape}" }.join(" && ")
  elsif options[:mode] == :perl
    command = "grep --perl-regexp #{text.shellescape} #{path.shellescape}"
  else
    command = "grep --basic-regexp #{text.shellescape} #{path.shellescape}"
  end
  remote_assert command
end

#has_directory(path) ⇒ Object



13
14
15
# File 'lib/baptize/plugins/base.rb', line 13

def has_directory(path)
  remote_assert("test -d #{path.shellescape}") or fail_verification("Remote directory #{path} does not exist")
end

#has_executable(path) ⇒ Object



36
37
38
# File 'lib/baptize/plugins/base.rb', line 36

def has_executable(path)
  remote_assert("which #{path.shellescape}") or fail_verification("No executable #{path} found")
end

#has_file(path) ⇒ Object



9
10
11
# File 'lib/baptize/plugins/base.rb', line 9

def has_file(path)
  remote_assert("test -e #{path.shellescape}") or fail_verification("Remote file #{path} does not exist")
end

#has_user(name) ⇒ Object



40
41
42
# File 'lib/baptize/plugins/base.rb', line 40

def has_user(name)
  remote_assert("id -u #{name.to_s.shellescape}") or fail_verification("No user #{name}")
end

#matches_local(local_path, remote_path) ⇒ Object



17
18
19
20
21
22
# File 'lib/baptize/plugins/base.rb', line 17

def matches_local(local_path, remote_path)
  raise VerificationFailure, "Couldn't find local file #{local_path}" unless ::File.exists?(local_path)
  require 'digest/md5'
  local_md5 = Digest::MD5.hexdigest(::File.read(local_path))
  md5_of_file(remote_path, local_md5) or fail_verification("Remote file #{remote_path} doesn't match local file #{local_path}")
end