Sha256: 607d23eb88391aa8ed953a40bc4ebf985fef7856991c5f320d3762a048259053

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 Bytes

Contents

require 'command_mapper/types/type'

module CommandMapper
  module Types
    #
    # Represents a path to an existing file or a directory.
    #
    class InputPath < Type

      #
      # Validates whether the path exists or not.
      #
      # @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.
      #
      # @api semipublic
      #
      def validate(value)
        unless value.empty?
          unless File.exists?(value)
            return [false, "path does not exist (#{value.inspect})"]
          end
        end

        return true
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
command_mapper-0.3.0 lib/command_mapper/types/input_path.rb
command_mapper-0.2.1 lib/command_mapper/types/input_path.rb