Sha256: e32000c4e991b2494d5aecdaf898ed679d4175870174f4944cd32f6ab74e5a0d

Contents?: true

Size: 814 Bytes

Versions: 3

Compression:

Stored size: 814 Bytes

Contents

require 'command_mapper/types/input_path'

module CommandMapper
  module Types
    #
    # Represents a path to an existing file.
    #
    class InputFile < InputPath

      #
      # Validates the file 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.file?(value)
            return [false, "file 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_file.rb
command_mapper-0.1.2 lib/command_mapper/types/input_file.rb
command_mapper-0.1.1 lib/command_mapper/types/input_file.rb