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.

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.



19
20
21
# File 'lib/factory_bot/internal.rb', line 19

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.



86
87
88
# File 'lib/factory_bot/internal.rb', line 86

def factory_by_name(name)
  factories.find(name)
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.



99
100
101
102
103
104
105
# File 'lib/factory_bot/internal.rb', line 99

def register_default_strategies
  register_strategy(:build, FactoryBot::Strategy::Build)
  register_strategy(:create, FactoryBot::Strategy::Create)
  register_strategy(:attributes_for, FactoryBot::Strategy::AttributesFor)
  register_strategy(:build_stubbed, FactoryBot::Strategy::Stub)
  register_strategy(:null, FactoryBot::Strategy::Null)
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.



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

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.



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

def register_inline_sequence(sequence)
  inline_sequences.push(sequence)
  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.



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

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.



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

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.



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

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.



23
24
25
# File 'lib/factory_bot/internal.rb', line 23

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.



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

def rewind_inline_sequences
  inline_sequences.each(&:rewind)
end

.rewind_sequence(*uri_parts) ⇒ 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.



63
64
65
66
67
68
69
70
# File 'lib/factory_bot/internal.rb', line 63

def rewind_sequence(*uri_parts)
  fail_argument_count(0, "1+") if uri_parts.empty?

  uri = build_uri(uri_parts)
  sequence = Sequence.find_by_uri(uri) || fail_unregistered_sequence(uri)

  sequence.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.



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

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.



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

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

.set_sequence(*uri_parts, value) ⇒ 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.



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

def set_sequence(*uri_parts, value)
  uri = build_uri(uri_parts) || fail_argument_count(uri_parts.size, "2+")
  sequence = Sequence.find(*uri) || fail_unregistered_sequence(uri)

  sequence.set_value(value)
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.



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

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

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



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

def trait_by_name(name, klass)
  traits.find(name).tap { |t| t.klass = klass }
end