Class: ROM::Factory::Structs

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/factory/factories.rb

Overview

In-memory builder API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registry, struct_namespace) ⇒ Structs

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 new instance of Structs.


25
26
27
28
# File 'lib/rom/factory/factories.rb', line 25

def initialize(registry, struct_namespace)
  @registry = registry
  @struct_namespace = struct_namespace
end

Instance Attribute Details

#registryObject (readonly)


18
19
20
# File 'lib/rom/factory/factories.rb', line 18

def registry
  @registry
end

#struct_namespaceObject (readonly)


22
23
24
# File 'lib/rom/factory/factories.rb', line 22

def struct_namespace
  @struct_namespace
end

Instance Method Details

#[](name, *traits, **attrs) ⇒ ROM::Struct

Build an in-memory struct

Examples:

create a struct with default attributes

MyFactory[:user]

create a struct with some attributes overridden

MyFactory.structs[:user, name: "Jane"]

Parameters:

  • name (Symbol)

    The name of the registered factory

  • attrs (Hash)

    An optional hash with attributes

Returns:

  • (ROM::Struct)

44
45
46
# File 'lib/rom/factory/factories.rb', line 44

def [](name, *traits, **attrs)
  registry[name].struct_namespace(struct_namespace).create(*traits, attrs)
end