2019-02-11 19:16:56 -05:00
|
|
|
module FactoryBot
|
|
|
|
# @api private
|
|
|
|
module Internal
|
|
|
|
class << self
|
2020-04-23 19:14:02 -04:00
|
|
|
delegate :after,
|
|
|
|
:before,
|
|
|
|
:callbacks,
|
|
|
|
:constructor,
|
2019-04-26 15:48:37 -04:00
|
|
|
:factories,
|
2020-04-23 19:14:02 -04:00
|
|
|
:initialize_with,
|
2019-04-26 15:48:37 -04:00
|
|
|
:inline_sequences,
|
|
|
|
:sequences,
|
2020-04-23 19:14:02 -04:00
|
|
|
:skip_create,
|
2019-04-26 15:48:37 -04:00
|
|
|
:strategies,
|
2020-04-23 19:14:02 -04:00
|
|
|
:to_create,
|
2019-04-26 15:48:37 -04:00
|
|
|
:traits,
|
|
|
|
to: :configuration
|
2019-02-13 17:24:28 -05:00
|
|
|
|
2019-02-11 19:16:56 -05:00
|
|
|
def configuration
|
|
|
|
@configuration ||= Configuration.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_configuration
|
|
|
|
@configuration = nil
|
|
|
|
end
|
2019-02-13 17:24:28 -05:00
|
|
|
|
|
|
|
def register_inline_sequence(sequence)
|
|
|
|
inline_sequences.push(sequence)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rewind_inline_sequences
|
|
|
|
inline_sequences.each(&:rewind)
|
|
|
|
end
|
2019-04-19 16:01:32 -04:00
|
|
|
|
|
|
|
def register_trait(trait)
|
|
|
|
trait.names.each do |name|
|
|
|
|
traits.register(name, trait)
|
|
|
|
end
|
|
|
|
trait
|
|
|
|
end
|
|
|
|
|
|
|
|
def trait_by_name(name)
|
|
|
|
traits.find(name)
|
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
def register_sequence(sequence)
|
|
|
|
sequence.names.each do |name|
|
|
|
|
sequences.register(name, sequence)
|
|
|
|
end
|
|
|
|
sequence
|
|
|
|
end
|
|
|
|
|
|
|
|
def sequence_by_name(name)
|
|
|
|
sequences.find(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rewind_sequences
|
|
|
|
sequences.each(&:rewind)
|
|
|
|
rewind_inline_sequences
|
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
def register_factory(factory)
|
|
|
|
factory.names.each do |name|
|
|
|
|
factories.register(name, factory)
|
|
|
|
end
|
|
|
|
factory
|
|
|
|
end
|
|
|
|
|
|
|
|
def factory_by_name(name)
|
|
|
|
factories.find(name)
|
|
|
|
end
|
2019-04-26 15:48:37 -04:00
|
|
|
|
|
|
|
def register_strategy(strategy_name, strategy_class)
|
|
|
|
strategies.register(strategy_name, strategy_class)
|
|
|
|
StrategySyntaxMethodRegistrar.new(strategy_name).define_strategy_methods
|
|
|
|
end
|
|
|
|
|
|
|
|
def strategy_by_name(name)
|
|
|
|
strategies.find(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def register_default_strategies
|
2020-04-23 19:14:02 -04:00
|
|
|
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)
|
2019-04-26 15:48:37 -04:00
|
|
|
end
|
2019-02-11 19:16:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|