class Slop::BoolOption

Cast the option argument to true or false. Override #default_value to default to false instead of nil. This option type does not expect an argument. However, the API supports value being passed. This is to ensure it can capture an explicit false value

Constants

FALSE_VALUES
TRUE_VALUES
VALID_VALUES

Attributes

explicit_value[RW]

Public Instance Methods

call(value) click to toggle source
# File lib/slop/types.rb, line 38
def call(value)
  self.explicit_value = value
  !force_false?
end
default_value() click to toggle source
# File lib/slop/types.rb, line 55
def default_value
  config[:default] || false
end
expects_argument?() click to toggle source
# File lib/slop/types.rb, line 59
def expects_argument?
  false
end
force_false?() click to toggle source
# File lib/slop/types.rb, line 51
def force_false?
  FALSE_VALUES.include?(explicit_value)
end
valid?(value) click to toggle source
# File lib/slop/types.rb, line 28
def valid?(value)
  # If we don't want to validate the type, then we don't care if the value
  # is valid or not. Otherwise we would prevent boolean flags followed by
  # arguments from being parsed correctly.
  return true unless config[:validate_type]

  return true if value.is_a?(String) && value.start_with?("--")
  value.nil? || VALID_VALUES.include?(value)
end
value() click to toggle source
Calls superclass method Slop::Option#value
# File lib/slop/types.rb, line 43
def value
  if force_false?
    false
  else
    super
  end
end