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
-
.after(key, event, &block) {|Object| ... } ⇒ Builder
Register a handler on a certain event.
-
.build(key, **attributes, &block) {|Object| ... } ⇒ Object
Builds an instance of the registered model class.
-
.create(key, **attributes, &block) {|Object| ... } ⇒ Object
Creates an instance of the registered model class.
-
.register ⇒ Zyra::Builder
Register a new builder.
-
.reset ⇒ NilClass
private
Resets the state of the registry.
Class Method Details
.after(key, event, &block) {|Object| ... } ⇒ Builder
Register a handler on a certain event
Possible events are build, create
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
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
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
36 |
# File 'lib/zyra.rb', line 36 delegate :register, to: :registry |
.reset ⇒ NilClass
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
90 91 92 |
# File 'lib/zyra.rb', line 90 def reset @registry = nil end |