Module: Taipo

Defined in:
lib/taipo.rb,
lib/taipo/cache.rb,
lib/taipo/check.rb,
lib/taipo/parser.rb,
lib/taipo/version.rb,
lib/taipo/utilities.rb,
lib/taipo/exceptions.rb,
lib/taipo/refinements.rb,
lib/taipo/parser/stack.rb,
lib/taipo/type_element.rb,
lib/taipo/type_elements.rb,
lib/taipo/parser/validater.rb,
lib/taipo/parser/syntax_state.rb,
lib/taipo/exceptions/name_error.rb,
lib/taipo/exceptions/type_error.rb,
lib/taipo/type_element/children.rb,
lib/taipo/exceptions/syntax_error.rb,
lib/taipo/type_element/constraint.rb,
lib/taipo/type_element/constraints.rb

Overview

A library for checking the types of objects

Taipo is primarily intended as a replacement for cumbersome, error-prone guard statements a user can put in their code to ensure that the variables they are handling conform to expectations.

By including the module Check, a user can call the Check#check or Check#review methods in their classes whenever a guard statement is necessary. Expectations are written as type definitions. A type definition contains the name of the type and the type definitions of any elements it contains (if it is enumerable). Optional constraints may be specified and sum types are also possible. See Parser::Validater for the full syntax.

Taipo works by:

  1. extracting the values of the arguments to be checked from a Binding;

  2. transforming the type definitions provided as Strings into an array of TypeElement instances; and

  3. checking whether the argument’s value matches any of the instances of TypeElement in the array.

As syntactic sugar, the Check module will by default alias Kernel#binding with the keyword types. This allows the user to call Check#check by writing check types (with a similar syntax for Check#review). If the user does not want to alias, they can set Taipo.alias= to false before including or extending Check.

See Also:

Since:

  • 1.0.0

Defined Under Namespace

Modules: Cache, Check, Parser, Refinements, Utilities Classes: NameError, SyntaxError, TypeElement, TypeElements, TypeError

Constant Summary collapse

VERSION =

Since:

  • 1.0.0

"1.4.0"
@@alias =

This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.

The setting for whether Kernel#binding should be aliased with the keyword types.

Since:

  • 1.1.0

true

Class Method Summary collapse

Class Method Details

.alias=(v) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set whether Kernel#binding should be aliased with the keyword types. Note that this will be reset to true whenever Check is extended or included.

Parameters:

  • v (Boolean)

    Whether to alias

Raises:

  • (::TypeError)

Since:

  • 1.1.0



51
52
53
54
55
56
# File 'lib/taipo.rb', line 51

def self.alias=(v)
  msg = "The argument to this method must be a Boolean."
  raise ::TypeError, msg unless v.is_a?(TrueClass) || v.is_a?(FalseClass)

  @@alias = v
end

.alias?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check whether Kernel#binding should be aliased with the keyword types.

Returns:

  • (Boolean)

    the result

Since:

  • 1.1.0



64
65
66
# File 'lib/taipo.rb', line 64

def self.alias?
  @@alias
end