Sha256: 202977acd6a8c76e0c1ab8137fcb1545f5664ec4d438d44446065e7864f04f34

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Sprinkle
  module Verifiers
    # = 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'}
    #
    module File
      Sprinkle::Verify.register(Sprinkle::Verifiers::File)
      
      # Checks to make sure <tt>path</tt> is a file on the remote server.
      def has_file(path)
        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
      
      def file_contains(path, text)
        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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lachlan-sprinkle-0.0.1 lib/sprinkle/verifiers/file.rb
lachlan-sprinkle-0.0.2 lib/sprinkle/verifiers/file.rb
lachlan-sprinkle-0.0.3 lib/sprinkle/verifiers/file.rb
lachlan-sprinkle-0.0.4 lib/sprinkle/verifiers/file.rb