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

Defined Under Namespace

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

Constant Summary collapse

DEFAULT_NAME =
"Factories"
VERSION =
"0.12.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

Parameters:

  • name (Symbol) (defaults to: DEFAULT_NAME)

    An optional factory class name

Returns:

  • (Class)


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, **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.



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

def fake(*args, **options)
  api = fetch_or_store(:faker, *args) do
    *ns, method_name = args

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

    const.method(method_name)
  end

  api.(**options)
end