Module: Capistrano::Baptize::Plugins::Base
- Defined in:
- lib/baptize/plugins/base.rb
Instance Method Summary collapse
- #file_contains(path, text, options = {}) ⇒ Object
- #has_directory(path) ⇒ Object
- #has_executable(path) ⇒ Object
- #has_file(path) ⇒ Object
- #has_user(name) ⇒ Object
- #matches_local(local_path, remote_path) ⇒ Object
Instance Method Details
#file_contains(path, text, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/baptize/plugins/base.rb', line 21 def file_contains(path, text, = {}) = {:mode => :text}.merge() if [:mode] == :text command = Array(text.strip.split("\n")).flatten.map {|line| "grep --fixed-strings #{line.shellescape} #{path.shellescape}" }.join(" && ") elsif [: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
10 11 12 |
# File 'lib/baptize/plugins/base.rb', line 10 def has_directory(path) raise VerificationFailure, "Remote directory #{path} does not exist" unless remote_assert("test -d #{path.shellescape}") end |
#has_executable(path) ⇒ Object
33 34 35 |
# File 'lib/baptize/plugins/base.rb', line 33 def has_executable(path) raise VerificationFailure, "No executable #{path} found" unless remote_assert "which #{path.shellescape}" end |
#has_file(path) ⇒ Object
6 7 8 |
# File 'lib/baptize/plugins/base.rb', line 6 def has_file(path) raise VerificationFailure, "Remote file #{path} does not exist" unless remote_assert("test -e #{path.shellescape}") end |
#has_user(name) ⇒ Object
37 38 39 |
# File 'lib/baptize/plugins/base.rb', line 37 def has_user(name) raise VerificationFailure, "No user #{name}" unless remote_assert "id -u #{name.to_s.shellescape}" end |
#matches_local(local_path, remote_path) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/baptize/plugins/base.rb', line 14 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)) raise VerificationFailure, "Remote file #{remote_path} doesn't match local file #{local_path}" unless md5_of_file(remote_path, local_md5) end |