Class: CommandMapper::Types::InputDir

Inherits:
InputPath show all
Defined in:
lib/command_mapper/types/input_dir.rb

Overview

Represents a path to an existing directory.

Instance Method Summary collapse

Methods inherited from Type

#format

Instance Method Details

#validate(value) ⇒ true, (false, String)

Validates whether the directory exists.

Parameters:

  • value (Object)

    The given value to validate.

Returns:

  • (true, (false, String))

    Returns true if the value is valid, or false and a validation error message if the value is not compatible.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/command_mapper/types/input_dir.rb', line 22

def validate(value)
  valid, message = super(value)

  unless valid
    return valid, message
  end

  unless value.empty?
    unless File.directory?(value)
      return [false, "directory does not exist (#{value.inspect})"]
    end
  end

  return true
end