Sha256: dace132f2ead7da29d0e0c6df0829d684ae769a3e16eb79a637d393fd5df1ecd

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

module Sprinkle
  module Verifiers
    # = Executable Verifier
    #
    # Contains a verifier to check the existance of an executable
    # script on your server.
    # 
    # == Example Usage
    #
    # First, absolute path to an executable:
    #
    #   verify { has_executable '/usr/special/secret/bin/scipt' }
    #
    # Second, a global executable which would be available anywhere on the
    # command line:
    #
    #   verify { has_executable 'grep' }
    module Executable
      Sprinkle::Verify.register(Sprinkle::Verifiers::Executable)
      
      # Checks if <tt>path</tt> is an executable script. This verifier is "smart" because
      # if the path contains a forward slash '/' then it assumes you're checking an 
      # absolute path to an executable. If no '/' is in the path, it assumes you're
      # checking for a global executable that would be available anywhere on the command line.
      def has_executable(path)
        path = path.to_s
        if RUBY_PLATFORM =~ /win32/
          raise NotImplementedError, "Win32 platform does not support checking for executables"
        else
          # Be smart: If the path includes a forward slash, we're checking
          # an absolute path. Otherwise, we're checking a global executable
          if path.include?('/')
            @commands << "test -x #{path}"
          else
            @commands << "[ -n \"`echo \\`which #{path}\\``\" ]"
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lachlan-sprinkle-0.0.10 lib/sprinkle/verifiers/executable.rb
lachlan-sprinkle-0.0.11 lib/sprinkle/verifiers/executable.rb
lachlan-sprinkle-0.0.13 lib/sprinkle/verifiers/executable.rb
lachlan-sprinkle-0.0.14 lib/sprinkle/verifiers/executable.rb
lachlan-sprinkle-0.0.9 lib/sprinkle/verifiers/executable.rb