Module: ObjectForge
- Defined in:
- lib/object_forge.rb,
lib/object_forge/forge.rb,
lib/object_forge/molds.rb,
lib/object_forge/version.rb,
lib/object_forge/crucible.rb,
lib/object_forge/sequence.rb,
lib/object_forge/forge_dsl.rb,
lib/object_forge/forgeyard.rb,
lib/object_forge/molds/hash_mold.rb,
lib/object_forge/un_basic_object.rb,
lib/object_forge/molds/struct_mold.rb,
lib/object_forge/molds/wrapped_mold.rb,
lib/object_forge/molds/keywords_mold.rb,
lib/object_forge/molds/single_argument_mold.rb
Overview
A small factory library for Ruby objects with minimal assumptions about framework, persistence, or runtime environment.
These are the main classes you should be aware of:
-
Forge is a factory for objects. Usually created through Forgeyard#define or Forge.define using a DSL similar to FactoryBot, Forges can be used standalone, or as a part of a Forgeyard.
-
Forgeyard is a registry of named related Forges. A Forgeyard allows to Forgeyard#define a Forge, and Forgeyard#forge a new object using a defined Forge.
-
Molds are object constructors used by Forges. Several common molds are shipped with ObjectForge, but you will probably find it useful to create your own.
Successful use may also depend on understanding these:
-
ForgeDSL is a block-based DSL inspired by FactoryBot and ROM::Factory. It allows defining arbitrary attributes (possibly using sequences), with support for traits (collections of attributes with non-default values).
-
Sequence is a representation of a sequence of values. They are usually used implicitly through ForgeDSL#sequence, but can be created explicitly to be shared (or used outside of ObjectForge).
-
Crucible is used to resolve attributes.
ObjectForge itself provides a top-level convenience API for working with a singular DEFAULT_YARD when you expect to never need more than one Forgeyard, such as in test suites.
Defined Under Namespace
Modules: Molds Classes: CircularAttributeDependencyError, Crucible, DSLError, Error, Forge, ForgeDSL, Forgeyard, ObjectInterfaceError, Sequence, UnBasicObject
Constant Summary collapse
Class Method Summary collapse
-
.define(name, forge_target) {|dsl| ... } ⇒ Forge
Define and create a forge in DEFAULT_YARD.
-
.forge(name, *traits, **overrides) {|object| ... } ⇒ Any
(also: build, call)
Build an instance using a forge from DEFAULT_YARD.
-
.sequence(initial) ⇒ Sequence
Create a sequence, to be used wherever it needs to be.
Class Method Details
.define(name, forge_target) {|dsl| ... } ⇒ Forge
Default forgeyard is intended to be useful for non-shareable code, like simple application tests and specs. It should not be used in application code, especially in gems.
Define and create a forge in DEFAULT_YARD.
149 150 151 |
# File 'lib/object_forge.rb', line 149 def self.define(...) DEFAULT_YARD.define(...) end |
.forge(name, *traits, **overrides) {|object| ... } ⇒ Any Also known as: build, call
Default forgeyard is intended to be useful for non-shareable code, like simple application tests and specs. It should not be used in application code, especially in gems.
Build an instance using a forge from DEFAULT_YARD.
168 169 170 |
# File 'lib/object_forge.rb', line 168 def self.forge(...) DEFAULT_YARD.forge(...) end |