1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Move registries to configuration

This commit is contained in:
Joshua Clayton 2012-05-12 10:27:47 -04:00
parent edb6eaf8af
commit 49392a6a31
3 changed files with 30 additions and 9 deletions

View file

@ -2,6 +2,7 @@ require 'set'
require 'active_support/core_ext/module/delegation'
require 'active_support/notifications'
require 'factory_girl/configuration'
require 'factory_girl/errors'
require 'factory_girl/factory_runner'
require 'factory_girl/strategy_syntax_method_registrar'
@ -39,8 +40,16 @@ require 'factory_girl/reload'
require 'factory_girl/version'
module FactoryGirl
def self.configuration
@configuration ||= Configuration.new
end
def self.reset_configuration
@configuration = nil
end
def self.factories
@factories ||= DisallowsDuplicatesRegistry.new(Registry.new('Factory'))
configuration.factories
end
def self.register_factory(factory)
@ -55,7 +64,7 @@ module FactoryGirl
end
def self.sequences
@sequences ||= DisallowsDuplicatesRegistry.new(Registry.new('Sequence'))
configuration.sequences
end
def self.register_sequence(sequence)
@ -70,7 +79,7 @@ module FactoryGirl
end
def self.traits
@traits ||= DisallowsDuplicatesRegistry.new(Registry.new('Trait'))
configuration.traits
end
def self.register_trait(trait)
@ -85,7 +94,7 @@ module FactoryGirl
end
def self.strategies
@strategies ||= Registry.new('Strategy')
configuration.strategies
end
def self.register_strategy(strategy_name, strategy_class)
@ -113,7 +122,7 @@ module FactoryGirl
end
def self.callback_names
@callback_names ||= Set.new
configuration.callback_names
end
def self.register_callback(name)

View file

@ -0,0 +1,14 @@
module FactoryGirl
# @api private
class Configuration
attr_reader :factories, :sequences, :traits, :strategies, :callback_names
def initialize
@factories = DisallowsDuplicatesRegistry.new(Registry.new('Factory'))
@sequences = DisallowsDuplicatesRegistry.new(Registry.new('Sequence'))
@traits = DisallowsDuplicatesRegistry.new(Registry.new('Trait'))
@strategies = Registry.new('Strategy')
@callback_names = Set.new
end
end
end

View file

@ -1,10 +1,8 @@
module FactoryGirl
def self.reload
self.factories.clear
self.sequences.clear
self.traits.clear
self.strategies.clear
self.reset_configuration
self.register_default_strategies
self.register_default_callbacks
self.find_definitions
end
end