Sha256: 0d02f6b05e4033e59b44e7db03d6d25b160735af8d79d9ce1b19d3dfbfbb8682

Contents?: true

Size: 893 Bytes

Versions: 1

Compression:

Stored size: 893 Bytes

Contents

require_relative 'arg'

module CommandMapper
  #
  # Represents the value for an option.
  #
  class OptionValue < Arg

    #
    # Validates whether a given value is compatible with the option {#type}.
    #
    # @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)
      if !required? && value == true
        return true
      else
        super(value)
      end
    end

    #
    # Formats a value using the options {#type}.
    #
    # @param [Object] value
    #   The given value to format.
    #
    # @return [String]
    #   The formatted value.
    #
    # @api semipublic
    #
    def format(value)
      @type.format(value)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
command_mapper-0.3.2 lib/command_mapper/option_value.rb