Sha256: d8fd9cdb4f9f8a93d007e5144acd31a69dfc283c916fcdb546ae7e04bcfe084b

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.5 lib/sprinkle/verifiers/file.rb
lachlan-sprinkle-0.0.6 lib/sprinkle/verifiers/file.rb
lachlan-sprinkle-0.0.7 lib/sprinkle/verifiers/file.rb
lachlan-sprinkle-0.0.8 lib/sprinkle/verifiers/file.rb