Class: Versionomy::Schema::Builder

Inherits:
Object
  • Object
show all
Includes:
Blockenspiel::DSL
Defined in:
lib/versionomy/schema/wrapper.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initializeBuilder

:nodoc:


200
201
202
203
204
205
# File 'lib/versionomy/schema/wrapper.rb', line 200

def initialize()  # :nodoc:
  @field = nil
  @modules = []
  @aliases = {}
  @defaults = { :integer => {}, :string => {}, :symbol => {} }
end

Instance Method Details

#_get_aliasesObject

:nodoc:


308
309
310
# File 'lib/versionomy/schema/wrapper.rb', line 308

def _get_aliases  # :nodoc:
  @aliases
end

#_get_default_setting(type_, setting_) ⇒ Object

:nodoc:


312
313
314
# File 'lib/versionomy/schema/wrapper.rb', line 312

def _get_default_setting(type_, setting_)  # :nodoc:
  @defaults[type_][setting_]
end

#_get_fieldObject

:nodoc:


300
301
302
# File 'lib/versionomy/schema/wrapper.rb', line 300

def _get_field  # :nodoc:
  @field
end

#_get_modulesObject

:nodoc:


304
305
306
# File 'lib/versionomy/schema/wrapper.rb', line 304

def _get_modules  # :nodoc:
  @modules
end

#add_module(mod_) ⇒ Object

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.


248
249
250
# File 'lib/versionomy/schema/wrapper.rb', line 248

def add_module(mod_)
  @modules << mod_
end

#alias_field(alias_name_, field_name_) ⇒ Object

Create a field alias.


239
240
241
# 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_) ⇒ Object

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.


295
296
297
# File 'lib/versionomy/schema/wrapper.rb', line 295

def default_value_for_type(type_, value_)
  @defaults[type_][:value] = value_
end

#field(name_, opts_ = {}, &block_) ⇒ Object

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.


229
230
231
232
233
234
# 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_) ⇒ Object

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.


259
260
261
# File 'lib/versionomy/schema/wrapper.rb', line 259

def to_bump_type(type_, &block_)
  @defaults[type_][:bump] = block_
end

#to_canonicalize_type(type_, &block_) ⇒ Object

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.


284
285
286
# File 'lib/versionomy/schema/wrapper.rb', line 284

def to_canonicalize_type(type_, &block_)
  @defaults[type_][:canonicalize] = block_
end

#to_compare_type(type_, &block_) ⇒ Object

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.


273
274
275
# File 'lib/versionomy/schema/wrapper.rb', line 273

def to_compare_type(type_, &block_)
  @defaults[type_][:compare] = block_
end