Module: Mixture::Extensions

Defined in:
lib/mixture/extensions.rb,
lib/mixture/extensions/hashable.rb,
lib/mixture/extensions/coercable.rb,
lib/mixture/extensions/validatable.rb,
lib/mixture/extensions/attributable.rb

Overview

All of the extensions of mixture. Handles registration of extensions, so that extensions can be referend by a name instead of the constant.

Defined Under Namespace

Modules: Attributable, Coercable, Hashable, Validatable

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Module

Loads an extension with the given name. If it cannot find the matching extension, it raises a KeyError.

Parameters:

  • name (Symbol)

    The name of the extension.

Returns:

  • (Module)

    The corresponding extension.

Raises:

  • (KeyError)

29
30
31
# File 'lib/mixture/extensions.rb', line 29

def self.[](name)
  extensions.fetch(name)
end

.extensionsHash{Symbol => Module}

The extensions that are registered with this module.

Returns:

  • (Hash{Symbol => Module})

36
37
38
# File 'lib/mixture/extensions.rb', line 36

def self.extensions
  @_extensions ||= {}
end

.finalizevoid

This method returns an undefined value.

Finalizes the extension module. It registers the extensions in Mixture.


44
45
46
47
48
49
# File 'lib/mixture/extensions.rb', line 44

def self.finalize
  register :attribute, Attributable
  register :coerce, Coercable
  register :hash, Hashable
  register :validate, Validatable
end

.register(name, extension) ⇒ Object

Registers an extension with the module. This maps a name to an extension. Extensions may be registered multiple times, with different names.

Parameters:

  • name (Symbol)

    The name of the extension to register.

  • extension (Module)

    The module to register.


19
20
21
# File 'lib/mixture/extensions.rb', line 19

def self.register(name, extension)
  extensions[name.to_s.downcase.intern] = extension
end