mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
4d1cb6219b
Why: These methods are used internally for the functionality of the library and are subject to change. Therefore shouldn't be part of the public interface. This PR: - Moves the ```register_factory``` and ```factory_by_name``` methods to the ```FactoryBot::Internal``` class. - Deprecates the use of ```register_factory``` and ```factory_by_name``` from the ```FactoryBot``` module. - Improve formatting of the specs
62 lines
1.3 KiB
Ruby
62 lines
1.3 KiB
Ruby
module FactoryBot
|
|
# @api private
|
|
module Internal
|
|
class << self
|
|
delegate :inline_sequences, :sequences, :traits, :factories, to: :configuration
|
|
|
|
def configuration
|
|
@configuration ||= Configuration.new
|
|
end
|
|
|
|
def reset_configuration
|
|
@configuration = nil
|
|
end
|
|
|
|
def register_inline_sequence(sequence)
|
|
inline_sequences.push(sequence)
|
|
end
|
|
|
|
def rewind_inline_sequences
|
|
inline_sequences.each(&:rewind)
|
|
end
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
end
|
|
end
|
|
end
|