class Versionomy::Schema::Builder

These methods are available in a schema definition block given to Versionomy::Schema#create.

Public Instance Methods

add_module(mod_) click to toggle source

Add a module to the schema. All values that use this schema will include this module. This provides a way to add schema-specific capabilities to version numbers.

# File lib/versionomy/schema/wrapper.rb, line 248
def add_module(mod_)
  @modules << mod_
end
alias_field(alias_name_, field_name_) click to toggle source

Create a field alias.

# File lib/versionomy/schema/wrapper.rb, line 239
def alias_field(alias_name_, field_name_)
  @aliases[alias_name_.to_sym] = field_name_.to_sym
end
default_value_for_type(type_, value_) click to toggle source

Provide a default value for the given type. The type should be :integer, :string, or :symbol. You must provide a default value that will be used for all fields of this type, unless explicitly overridden by the field.

# File lib/versionomy/schema/wrapper.rb, line 295
def default_value_for_type(type_, value_)
  @defaults[type_][:value] = value_
end
field(name_, opts_={}, &block_) click to toggle source

Create the root field.

Recognized options include:

: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 Versionomy::Schema::FieldBuilder to customize this field.

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

Raises Versionomy::Errors::RangeOverlapError if a root field has already been created.

# File lib/versionomy/schema/wrapper.rb, line 229
def field(name_, opts_={}, &block_)
  if @field
    raise Errors::RangeOverlapError, "Root field already defined"
  end
  @field = Schema::Field.new(name_, opts_.merge(:master_builder => self), &block_)
end
to_bump_type(type_, &block_) click to toggle source

Provide a default bump procedure for the given type. The type should be :integer, :string, or :symbol. You must provide a block that takes a field value and returns the “bumped” value. This procedure will be used for all fields of this type, unless explicitly overridden by the field.

# File lib/versionomy/schema/wrapper.rb, line 259
def to_bump_type(type_, &block_)
  @defaults[type_][:bump] = block_
end
to_canonicalize_type(type_, &block_) click to toggle source

Provide a default canonicalization procedure for the given type. The type should be :integer, :string, or :symbol. You must provide a block that takes a field value and returns the canonical value. This procedure will be used for all fields of this type, unless explicitly overridden by the field.

# File lib/versionomy/schema/wrapper.rb, line 284
def to_canonicalize_type(type_, &block_)
  @defaults[type_][:canonicalize] = block_
end
to_compare_type(type_, &block_) click to toggle source

Provide a default compare procedure for the given type. The type should be :integer, :string, or :symbol. You must provide a block that takes two values and returns a standard comparison result– that is, a negative integer if the first value is less, 0 if the values are equal, or a positive integer if the first value is greater. This procedure will be used for all fields of this type, unless explicitly overridden by the field.

# File lib/versionomy/schema/wrapper.rb, line 273
def to_compare_type(type_, &block_)
  @defaults[type_][:compare] = block_
end