Module: Sprinkle::Verifiers::File

Defined in:
lib/sprinkle/verifiers/file.rb

Overview

File Verifier

Contains a verifier to check the existance of a file.

Example Usage

verify { has_file '/etc/apache2/apache2.conf' }

verify { file_contains '/etc/apache2/apache2.conf', 'mod_gzip'}

Instance Method Summary collapse

Instance Method Details

#file_contains(path, text) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/sprinkle/verifiers/file.rb', line 28

def file_contains(path, text)
  path, text = path.to_s, text.to_s
  if RUBY_PLATFORM =~ /win32/
    command = "findstr /m /c:\"#{text}\" \"#{path}\""
    command << ' > NUL 2>&1' unless logger.debug?
  else
    command = "grep '#{text}' #{path}"
  end
  @commands << command
end

#has_file(path) ⇒ Object

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



17
18
19
20
21
22
23
24
25
26
# File 'lib/sprinkle/verifiers/file.rb', line 17

def has_file(path)
  path = path.to_s
  if RUBY_PLATFORM =~ /win32/
    command = "if exist \"#{path}\" (if not exist \"#{path}\\\" (exit 0) else (exit 1)) else (exit 1)"
    command << ' > NUL 2>&1' unless logger.debug?
  else
    command = "test -f #{path}"
  end
  @commands << command
end