Module: ROM::Factory

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/factories.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, Structs, TupleEvaluator

Constant Summary collapse

DEFAULT_NAME =
'Factories'.freeze
VERSION =
'0.5.0'.freeze

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)


23
24
25
26
27
# File 'lib/rom/factory.rb', line 23

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

.fake(type, *args) ⇒ 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.



11
12
13
14
15
16
17
18
19
20
# File 'lib/rom/factory/dsl.rb', line 11

def self.fake(type, *args)
  api = Faker.const_get(Dry::Core::Inflector.classify(type.to_s))
  meth, *rest = args

  if meth.is_a?(Symbol)
    api.public_send(meth, *rest)
  else
    api.public_send(type, *args)
  end
end