Class: Rake::FileTask

Inherits:
Object show all
Defined in:
lib/buildr/core/checks.rb

Instance Method Summary collapse

Instance Method Details

#contain?(*patterns) ⇒ Boolean

:call-seq:

contain?(pattern*) => boolean
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).

Returns:

  • (Boolean)


241
242
243
244
245
246
247
248
249
# File 'lib/buildr/core/checks.rb', line 241

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

:call-seq:

empty?() => boolean

Returns true if file/directory is empty.

Returns:

  • (Boolean)


228
229
230
# File 'lib/buildr/core/checks.rb', line 228

def empty?()
  File.directory?(name) ? Dir.glob("#{name}/*").empty? : File.read(name).empty?
end

#exist?Boolean

:call-seq:

exist?() => boolean

Returns true if this file exists.

Returns:

  • (Boolean)


220
221
222
# File 'lib/buildr/core/checks.rb', line 220

def exist?()
  File.exist?(name)
end