Module: ROM::Factory

Extended by:
Dry::Core::Cache
Includes:
Dry::Core::Constants
Defined in:
lib/rom/factory.rb,
lib/rom/factory/dsl.rb,
lib/rom/factory/builder.rb,
lib/rom/factory/version.rb,
lib/rom/factory/registry.rb,
lib/rom/factory/constants.rb,
lib/rom/factory/factories.rb,
lib/rom/factory/sequences.rb,
lib/rom/factory/attributes.rb,
lib/rom/factory/tuple_evaluator.rb,
lib/rom/factory/attributes/value.rb,
lib/rom/factory/attribute_registry.rb,
lib/rom/factory/attributes/callable.rb,
lib/rom/factory/attributes/sequence.rb,
lib/rom/factory/builder/persistable.rb,
lib/rom/factory/attributes/association.rb

Overview

Main ROM::Factory API

API:

  • public

Defined Under Namespace

Modules: Attributes Classes: AttributeRegistry, Builder, DSL, Factories, FactoryNotDefinedError, Registry, Sequences, Structs, TupleEvaluator, UnknownFactoryAttributes

Constant Summary collapse

DEFAULT_NAME =

API:

  • public

"Factories"
VERSION =

API:

  • public

"0.13.0"

Class Method Summary collapse

Class Method Details

.configure(name = DEFAULT_NAME, &block) ⇒ Class

Configure a new factory

Examples:

MyFactory = ROM::Factory.configure do |config|
  config.rom = my_rom_container
end

API:

  • public

Parameters:

  • (defaults to: DEFAULT_NAME)

    An optional factory class name

Returns:



28
29
30
31
32
33
34
# File 'lib/rom/factory.rb', line 28

def self.configure(name = DEFAULT_NAME, &block)
  klass = Dry::Core::ClassBuilder.new(name: name, parent: Factories).call do |c|
    c.configure(&block)
  end

  klass.new(klass.config.rom)
end

.fake(*args, unique: false, **options) ⇒ Object

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.

API:

  • private



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rom/factory/dsl.rb', line 15

def fake(*args, unique: false, **options)
  factory, produce = fetch_or_store(:faker, unique, *args) do
    *ns, method_name = args

    const = ns.reduce(::Faker) do |obj, name|
      obj.const_get(::ROM::Inflector.camelize(name))
    end

    if unique
      [const.unique, method_name]
    else
      [const, method_name]
    end
  end

  factory.public_send(produce, **options)
end