Module: Ore::Checks

Included in:
Project
Defined in:
lib/ore/checks.rb

Overview

A mixin for Project which provides methods for checking files.

Instance Method Summary collapse

Instance Method Details

#check_directory(path) {|path| ... } ⇒ Object (protected)

Checks if the path is a readable directory.

Yields:

  • (path)

    The block will be passed the path, if it is a readable directory. Otherwise a warning will be printed.

Yield Parameters:

  • path (String)

    The directory path.



36
37
38
39
40
41
42
43
44
# File 'lib/ore/checks.rb', line 36

def check_directory(path)
  check_readable(path) do |dir|
    if File.directory?(dir)
      yield dir
    else
      warn "#{dir} is not a directory!"
    end
  end
end

#check_executable(path) {|path| ... } ⇒ Object (protected)

Checks if the path is an executable file.

Yields:

  • (path)

    The block will be passed the path, if it is an executable file. Otherwise a warning will be printed.

Yield Parameters:

  • path (String)

    An path to an executable file.



78
79
80
81
82
83
84
85
86
# File 'lib/ore/checks.rb', line 78

def check_executable(path)
  check_file(path) do |file|
    if File.executable?(file)
      yield file
    else
      warn "#{file} is not executable!"
    end
  end
end

#check_file(path) {|path| ... } ⇒ Object (protected)

Checks if the path is a readable file.

Yields:

  • (path)

    The block will be passed the path, if it is a readable file. Otherwise a warning will be printed.

Yield Parameters:

  • path (String)

    A file path.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ore/checks.rb', line 56

def check_file(path)
  if @project_files.include?(path)
    check_readable(path) do |file|
      if File.file?(file)
        yield file
      else
        warn "#{file} is not a file!"
      end
    end
  end
end

#check_readable(path) {|path| ... } ⇒ Object (protected)

Checks if the path is readable.

Yields:

  • (path)

    The block will be passed the path, if it is readable. Otherwise a warning will be printed.

Yield Parameters:

  • path (String)

    A readable path.



18
19
20
21
22
23
24
# File 'lib/ore/checks.rb', line 18

def check_readable(path)
  if File.readable?(path)
    yield path
  else
    warn "#{path} is not readable!"
  end
end