Class: Minitag::ExtensionRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/minitag/extension_registry.rb

Overview

Stores and extends classes that relies on tags with the Minitag::TagExtension module.

Instance Method Summary collapse

Constructor Details

#initializeExtensionRegistry

Returns a new instance of ExtensionRegistry.



7
8
9
# File 'lib/minitag/extension_registry.rb', line 7

def initialize
  @registry = {}
end

Instance Method Details

#register(klass) ⇒ void

This method returns an undefined value.

Extends a class with Minitag::TagExtension and stores it as extended.

Invariants:

- Classes that were already extended will be ignored during this operation.

Parameters:

  • klass (Class)

    a class that will be extended.



19
20
21
22
23
24
# File 'lib/minitag/extension_registry.rb', line 19

def register(klass)
  return if @registry.key?(klass)

  @registry[klass] = true
  klass.singleton_class.prepend(Minitag::TagExtension)
end