class Rake::FileTask

Public Instance Methods

contain?(pattern*) → boolean click to toggle source
contain?(file*) → boolean

For a file, returns true if the file content matches against all the arguments. An argument may be a string or regular expression.

For a directory, return true if the directory contains the specified files. You can use relative file names and glob patterns (using *, **, etc).

# File lib/buildr/core/checks.rb, line 233
def contain?(*patterns)
  if File.directory?(name)
    patterns.map { |pattern| "#{name}/#{pattern}" }.all? { |pattern| !Dir[pattern].empty? }
  else
    contents = File.read(name)
    patterns.map { |pattern| Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern.to_s)) }.
      all? { |pattern| contents =~ pattern }
  end
end
empty?() → boolean click to toggle source

Returns true if file/directory is empty.

# File lib/buildr/core/checks.rb, line 220
def empty?()
  File.directory?(name) ? Dir.glob("#{name}/*").empty? : File.read(name).empty?
end
exist?() → boolean click to toggle source

Returns true if this file exists.

# File lib/buildr/core/checks.rb, line 212
def exist?()
  File.exist?(name)
end