Class Versionomy::Schema::FieldBuilder
In: lib/versionomy/schema/field.rb
Parent: Object

These methods are available in a schema field definition block.

Methods

Included Modules

::Blockenspiel::DSL

Public Instance methods

Provide a default value.

Add a child field.

Recognized options include:

:only:The child should be available only for the given values of this field. See below for ways to specify this constraint.
:type:Type of field. This should be :integer, :string, or :symbol. Default is :integer.
:default_value:Default value for the field if no value is explicitly set. Default is 0 for an integer field, the empty string for a string field, or the first symbol added for a symbol field.

You may provide an optional block. Within the block, you may call methods of this class again to customize the child.

Raises Versionomy::Errors::IllegalValueError if the given default value is not legal.

The :only constraint may be specified in one of the following ways:

  • A single value (integer, string, or symbol)
  • The result of calling range() to define an inclusive range of integers, strings, or symbols. In this case, either element may be nil, specifying an open end of the range. If the field type is symbol, the ordering of symbols for the range is defined by the order in which the symbols were added to this schema.
  • A Range object defining a range of integers or strings. Only inclusive, not exclusive, ranges are supported.
  • An array of the above.

Raises Versionomy::Errors::RangeSpecificationError if the given ranges are not legal.

Raises Versionomy::Errors::RangeOverlapError if the given ranges overlap previously specified ranges, or more than one default schema is specified.

Define a range for the :only parameter to child.

This creates an object that child interprets like a standard ruby Range. However, it is customized for the use of child in the following ways:

  • It supports only inclusive, not exclusive ranges.
  • It supports open-ended ranges by setting either endpoint to nil.
  • It supports symbol ranges under Ruby 1.8.

Define the given symbol.

Recognized options include:

:bump:The symbol to transition to when "bump" is called. Default is to remain on the same value.

Raises Versionomy::Errors::TypeMismatchError if called when the current field is not of type :symbol.

Raises Versionomy::Errors::SymbolRedefinedError if the given symbol name is already defined.

Provide a "bump" procedure. The given block should take a value, and return the value to transition to. If you return nil, the value will remain the same.

Provide a "canonicalize" procedure. The given block should take a value and return a canonicalized value. Return nil if the given value is illegal.

Provide a "compare" procedure. The given block should take two values and compare them. It should return a negative integer if the first is less than the second, a positive integer if the first is greater than the second, or 0 if the two values are equal. If the values cannot be compared, return nil.

[Validate]