Class: Toys::Settings::Type

Inherits:
Object
  • Object
show all
Defined in:
core-docs/toys/settings.rb

Overview

Defined in the toys-core gem

A type object that checks values.

A Type includes a description string and a testing function. The testing function takes a proposed value and returns either the value itself if it is valid, a converted value if the value can be converted to a valid value, or ILLEGAL_VALUE if the type check failed.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, &block) ⇒ Type

Create a new Type.

Parameters:

  • description (String)

    Name of the type.

  • block (Proc)

    A testing function.



354
355
356
# File 'core-docs/toys/settings.rb', line 354

def initialize(description, &block)
  # Source available in the toys-core gem
end

Instance Attribute Details

#descriptionString (readonly)

The name of the type.

Returns:

  • (String)


362
363
364
# File 'core-docs/toys/settings.rb', line 362

def description
  @description
end

Class Method Details

.for_default_value(value) ⇒ Type

Create and return a Type given a default value. See the Toys::Settings class documentation for the rules.

Parameters:

  • value (Object)

Returns:



395
396
397
# File 'core-docs/toys/settings.rb', line 395

def for_default_value(value)
  # Source available in the toys-core gem
end

.for_type_spec(type_spec) ⇒ Type

Create and return a Type given a type specification. See the Toys::Settings class documentation for valid type specifications.

Parameters:

  • type_spec (Object)

Returns:

Raises:

  • (ArgumentError)

    if the type specification is invalid.



384
385
386
# File 'core-docs/toys/settings.rb', line 384

def for_type_spec(type_spec)
  # Source available in the toys-core gem
end

Instance Method Details

#call(val) ⇒ Object

Test a value, possibly converting to a legal value.

Parameters:

  • val (Object)

    The value to be tested.

Returns:

  • (Object)

    The validated value, the value converted to a legal value, or ILLEGAL_VALUE if the type check is unsuccessful.



371
372
373
# File 'core-docs/toys/settings.rb', line 371

def call(val)
  # Source available in the toys-core gem
end