Sha256: fd875e167d0c583e2dc0dd0733ed7e23fd15527b671f71eab7af7a353cd61282

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

module Ore
  module Checks
    protected

    #
    # Checks if the path is readable.
    #
    # @yield [path]
    #   The block will be passed the path, if it is readable.
    #   Otherwise a warning will be printed.
    #
    # @yieldparam [String] path
    #   A readable path.
    #
    def check_readable(path)
      if File.readable?(path)
        yield path
      else
        warn "#{path} is not readable!"
      end
    end

    #
    # Checks if the path is a readable directory.
    #
    # @yield [path]
    #   The block will be passed the path, if it is a readable directory.
    #   Otherwise a warning will be printed.
    #
    # @yieldparam [String] path
    #   The directory path.
    #
    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

    #
    # Checks if the path is a readable file.
    #
    # @yield [path]
    #   The block will be passed the path, if it is a readable file.
    #   Otherwise a warning will be printed.
    #
    # @yieldparam [String] path
    #   A file path.
    #
    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

    #
    # Checks if the path is an executable file.
    #
    # @yield [path]
    #   The block will be passed the path, if it is an executable file.
    #   Otherwise a warning will be printed.
    #
    # @yieldparam [String] path
    #   An path to an executable file.
    #
    def check_executable(path)
      check_file(path) do |file|
        if File.executable?(file)
          yield file
        else
          warn "#{file} is not executable!"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ore-0.1.3 lib/ore/checks.rb
ore-0.1.2 lib/ore/checks.rb