Class: Zyra::Registry Private

Inherits:
Object
  • Object
show all
Defined in:
lib/zyra/registry.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Registry of all registered builders

Instance Method Summary collapse

Instance Method Details

#builder_for(key) ⇒ Zyra::Builder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a registered builder

when the builder was not registerd, nil is returned

Parameters:

  • key (String, Symbol)

    key under which the builder is registered

Returns:



20
21
22
# File 'lib/zyra/registry.rb', line 20

def builder_for(key)
  registry[key.to_sym]
end

#register(klass) ⇒ Zyra::Builder #register(klass, key) ⇒ Zyra::Builder

Register a new builder

The builder will focus on one class and be registered under a symbol key

Overloads:

  • #register(klass) ⇒ Zyra::Builder

    When the key is not provided, it is infered from the class name

  • #register(klass, key) ⇒ Zyra::Builder

    Parameters:

    • key (String, Symbol)

      key to be used when storyin the builder

Parameters:

  • klass (Class)

    Model class to be used by the builder

Returns:



9
10
11
# File 'lib/zyra/registry.rb', line 9

def register(klass, key = klass.name.gsub(/::([A-Z])/, '_\1').downcase)
  registry[key.to_sym] = Builder.new(klass)
end