From d2a30d6fd2e7c10bbbb28ef7820bfe3d075c241f Mon Sep 17 00:00:00 2001 From: Daniel Colson Date: Mon, 11 Feb 2019 19:16:56 -0500 Subject: [PATCH] Introduce FactoryBot::Internal module The `FactoryBot` module has a mixture of methods that are meant for use by people using the library, and methods that are meant only for internal use. The methods meant for internal use are cluttering the documentation, and may be confusing to users. This change was prompted by [#1258]. Rather than introduce yet another public method on `FactoryBot` meant only for internal use, we can introduce a `FactoryBot::Internal` module, and avoid generating documentation for that module. The `FactoryBot::Internal.register_inline_sequence` method in [#1258] will need access to the configuration instance, so this PR moves that into `FactoryBot::Internal`. Eventually I plan to deprecate `FactoryBot.configuration` and `FactoryBot.reset_configuration`, and to move more of the `FactoryBot` methods into `FactoryBot::Internal`, but I would rather hold off on all that until the dust settles on the 5.0 release. [#1258]: https://github.com/thoughtbot/factory_bot/pull/1258 --- lib/factory_bot.rb | 5 +++-- lib/factory_bot/internal.rb | 14 ++++++++++++++ lib/factory_bot/reload.rb | 2 +- lib/factory_bot/syntax/default.rb | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 lib/factory_bot/internal.rb diff --git a/lib/factory_bot.rb b/lib/factory_bot.rb index feebbf1..f6437df 100644 --- a/lib/factory_bot.rb +++ b/lib/factory_bot.rb @@ -45,16 +45,17 @@ require "factory_bot/decorator/invocation_tracker" require "factory_bot/decorator/new_constructor" require "factory_bot/linter" require "factory_bot/version" +require "factory_bot/internal" module FactoryBot DEPRECATOR = ActiveSupport::Deprecation.new("6.0", "factory_bot") def self.configuration - @configuration ||= Configuration.new + Internal.configuration end def self.reset_configuration - @configuration = nil + Internal.reset_configuration end mattr_accessor :use_parent_strategy, instance_accessor: false diff --git a/lib/factory_bot/internal.rb b/lib/factory_bot/internal.rb new file mode 100644 index 0000000..2caaea7 --- /dev/null +++ b/lib/factory_bot/internal.rb @@ -0,0 +1,14 @@ +module FactoryBot + # @api private + module Internal + class << self + def configuration + @configuration ||= Configuration.new + end + + def reset_configuration + @configuration = nil + end + end + end +end diff --git a/lib/factory_bot/reload.rb b/lib/factory_bot/reload.rb index 171f12f..082d700 100644 --- a/lib/factory_bot/reload.rb +++ b/lib/factory_bot/reload.rb @@ -1,6 +1,6 @@ module FactoryBot def self.reload - reset_configuration + Internal.reset_configuration register_default_strategies register_default_callbacks find_definitions diff --git a/lib/factory_bot/syntax/default.rb b/lib/factory_bot/syntax/default.rb index dd7da30..c1381c4 100644 --- a/lib/factory_bot/syntax/default.rb +++ b/lib/factory_bot/syntax/default.rb @@ -54,7 +54,7 @@ module FactoryBot private def configuration - FactoryBot.configuration + FactoryBot::Internal.configuration end end