Sha256: 4324b287e7434f51b82f6eec3348d40f900e61a396be521365100ba9e57b9298

Contents?: true

Size: 820 Bytes

Versions: 5

Compression:

Stored size: 820 Bytes

Contents

module Alf
  module Types

    # Defines the Boolean type which is missing to ruby.
    Boolean = Myrrha::Boolean

    # Converts commandline arguments to a Boolean.
    #
    # This method requires `argv` to be either empty or a singleton array.
    # When empty, `opts[:default]` is used. The value must be coercable
    # to a Boolean, according to Myrrha::Boolean coercions.
    #
    # @param [Array] argv commandline arguments
    # @params [Hash] opts options (not used)
    # @raise [ArgumentError] is the coercion fails
    def Boolean.from_argv(argv, opts={})
      raise ArgumentError if argv.size > 1
      value = argv.first || opts[:default] || false
      Tools.coerce(value, Boolean)
    rescue CoercionError
      raise ArgumentError, "Unable to coerce `#{value.inspect}` to Boolean"
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 lib/alf/types/boolean.rb
alf-0.12.1 lib/alf/types/boolean.rb
alf-0.12.0 lib/alf/types/boolean.rb
alf-0.11.1 lib/alf/types/boolean.rb
alf-0.11.0 lib/alf/types/boolean.rb