Module: Zyra

Defined in:
lib/zyra.rb,
lib/zyra/builder.rb,
lib/zyra/version.rb,
lib/zyra/registry.rb,
lib/zyra/exceptions.rb

Overview

Zyra allows builders to be registered to ease up seeding

Defined Under Namespace

Modules: Exceptions Classes: Builder, Registry

Constant Summary collapse

VERSION =
'0.0.2'

Class Method Summary collapse

Class Method Details

.after(key, event, &block) {|Object| ... } ⇒ Builder

Register a handler on a certain event

Possible events are build, create

Parameters:

  • key (String, Symbol)

    key under which the builder is registered

  • event (Symbol, String)

    event to be watched.

  • block (Proc)

    block to be executed when the event is called

Yields:

  • (Object)

    the model built

Returns:



49
50
51
# File 'lib/zyra.rb', line 49

def after(key, event, &block)
  builder_for(key).after(event, &block)
end

.build(key, **attributes, &block) {|Object| ... } ⇒ Object

Builds an instance of the registered model class

Parameters:

  • key (String, Symbol)

    key under which the builder is registered

  • attributes (Hash)

    attributes to be set in the model

  • block (Proc)

    block to be ran after where more attributes

Yields:

  • (Object)

    Instance of the model class

Returns:

  • (Object)

    an instance of model class

See Also:



65
66
67
# File 'lib/zyra.rb', line 65

def build(key, **attributes, &block)
  builder_for(key).build(**attributes, &block)
end

.create(key, **attributes, &block) {|Object| ... } ⇒ Object

Creates an instance of the registered model class

This behaves like build, but persists the entry

Parameters:

  • key (String, Symbol)

    key under which the builder is registered

  • attributes (Hash)

    attributes to be set in the model

  • block (Proc)

    block to be ran after where more attributes

Yields:

  • (Object)

    Instance of the model class

Returns:

  • (Object)

    an instance of model class

See Also:



79
80
81
# File 'lib/zyra.rb', line 79

def create(key, **attributes, &block)
  builder_for(key).create(**attributes, &block)
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:



36
# File 'lib/zyra.rb', line 36

delegate :register, to: :registry

.resetNilClass

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.

Resets the state of the registry

This is mainly used for testing

Returns:

  • (NilClass)


90
91
92
# File 'lib/zyra.rb', line 90

def reset
  @registry = nil
end