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)


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

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

.extensionsHash{Symbol => Module}

The extensions that are registered with this module.

Returns:

  • (Hash{Symbol => Module})


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

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

.finalizevoid

This method returns an undefined value.

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



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

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.



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

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