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.



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

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

Instance Attribute Details

#descriptionString (readonly)

The name of the type.

Returns:

  • (String)


369
370
371
# File 'core-docs/toys/settings.rb', line 369

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:



402
403
404
# File 'core-docs/toys/settings.rb', line 402

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.



391
392
393
# File 'core-docs/toys/settings.rb', line 391

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.



378
379
380
# File 'core-docs/toys/settings.rb', line 378

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