Sha256: c44d1a68a42558f3d1e131987c37697287122d408d032174845169d300b91f6d

Contents?: true

Size: 841 Bytes

Versions: 3

Compression:

Stored size: 841 Bytes

Contents

require 'command_mapper/types/input_path'

module CommandMapper
  module Types
    #
    # Represents a path to an existing directory.
    #
    class InputDir < InputPath

      #
      # Validates whether the directory exists.
      #
      # @param [Object] value
      #   The given value to validate.
      #
      # @return [true, (false, String)]
      #   Returns true if the value is valid, or `false` and a validation error
      #   message if the value is not compatible.
      #
      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

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
command_mapper-0.2.0 lib/command_mapper/types/input_dir.rb
command_mapper-0.1.2 lib/command_mapper/types/input_dir.rb
command_mapper-0.1.1 lib/command_mapper/types/input_dir.rb