Module: FactoryBot::Internal Private

Defined in:
lib/factory_bot/internal.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Constant Summary collapse

DEFAULT_STRATEGIES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  build: FactoryBot::Strategy::Build,
  create: FactoryBot::Strategy::Create,
  attributes_for: FactoryBot::Strategy::AttributesFor,
  build_stubbed: FactoryBot::Strategy::Stub,
  null: FactoryBot::Strategy::Null,
}.freeze
DEFAULT_CALLBACKS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[
  :after_create, :after_build, :after_stub, :after_create
].freeze

Class Method Summary collapse

Class Method Details

.configurationObject

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.



25
26
27
# File 'lib/factory_bot/internal.rb', line 25

def configuration
  @configuration ||= Configuration.new
end

.factory_by_name(name) ⇒ 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.



75
76
77
# File 'lib/factory_bot/internal.rb', line 75

def factory_by_name(name)
  factories.find(name)
end

.register_callback(name) ⇒ 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.



96
97
98
99
# File 'lib/factory_bot/internal.rb', line 96

def register_callback(name)
  name = name.to_sym
  callback_names << name
end

.register_default_callbacksObject

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.



92
93
94
# File 'lib/factory_bot/internal.rb', line 92

def register_default_callbacks
  DEFAULT_CALLBACKS.each(&method(:register_callback))
end

.register_default_strategiesObject

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.



88
89
90
# File 'lib/factory_bot/internal.rb', line 88

def register_default_strategies
  DEFAULT_STRATEGIES.each { |name, klass| register_strategy(name, klass) }
end

.register_factory(factory) ⇒ 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.



68
69
70
71
72
73
# File 'lib/factory_bot/internal.rb', line 68

def register_factory(factory)
  factory.names.each do |name|
    factories.register(name, factory)
  end
  factory
end

.register_inline_sequence(sequence) ⇒ 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.



33
34
35
# File 'lib/factory_bot/internal.rb', line 33

def register_inline_sequence(sequence)
  inline_sequences.push(sequence)
end

.register_sequence(sequence) ⇒ 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.



52
53
54
55
56
57
# File 'lib/factory_bot/internal.rb', line 52

def register_sequence(sequence)
  sequence.names.each do |name|
    sequences.register(name, sequence)
  end
  sequence
end

.register_strategy(strategy_name, strategy_class) ⇒ 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.



79
80
81
82
# File 'lib/factory_bot/internal.rb', line 79

def register_strategy(strategy_name, strategy_class)
  strategies.register(strategy_name, strategy_class)
  StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
end

.register_trait(trait) ⇒ 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.



41
42
43
44
45
46
# File 'lib/factory_bot/internal.rb', line 41

def register_trait(trait)
  trait.names.each do |name|
    traits.register(name, trait)
  end
  trait
end

.reset_configurationObject

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.



29
30
31
# File 'lib/factory_bot/internal.rb', line 29

def reset_configuration
  @configuration = nil
end

.rewind_inline_sequencesObject

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.



37
38
39
# File 'lib/factory_bot/internal.rb', line 37

def rewind_inline_sequences
  inline_sequences.each(&:rewind)
end

.rewind_sequencesObject

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.



63
64
65
66
# File 'lib/factory_bot/internal.rb', line 63

def rewind_sequences
  sequences.each(&:rewind)
  rewind_inline_sequences
end

.sequence_by_name(name) ⇒ 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.



59
60
61
# File 'lib/factory_bot/internal.rb', line 59

def sequence_by_name(name)
  sequences.find(name)
end

.strategy_by_name(name) ⇒ 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.



84
85
86
# File 'lib/factory_bot/internal.rb', line 84

def strategy_by_name(name)
  strategies.find(name)
end

.trait_by_name(name) ⇒ 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.



48
49
50
# File 'lib/factory_bot/internal.rb', line 48

def trait_by_name(name)
  traits.find(name)
end