Class: CommandMapper::Types::InputPath

Inherits:
Type
  • Object
show all
Defined in:
lib/command_mapper/types/input_path.rb

Overview

Represents a path to an existing file or a directory.

Direct Known Subclasses

InputDir, InputFile

Instance Method Summary collapse

Methods inherited from Type

#format

Instance Method Details

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

Validates whether the path exists or not.

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
# File 'lib/command_mapper/types/input_path.rb', line 22

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

  return true
end