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.



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

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.



82
83
84
85
86
87
88
# File 'lib/factory_bot/internal.rb', line 82

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.



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

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
# File 'lib/factory_bot/internal.rb', line 27

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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