diff --git a/Rakefile b/Rakefile index d5ed99347..78dd7a29d 100644 --- a/Rakefile +++ b/Rakefile @@ -76,7 +76,7 @@ namespace :docs do instance_methods_to_document = meths.select { |method| method.scope != :class } class_methods_to_document = meths.select { |method| method.scope == :class } - configuration_methods_to_document = registry.get("ViewComponent::Config").meths.select(&:reader?) + configuration_methods_to_document = registry.get("ViewComponent::GlobalConfig").meths.select(&:reader?) test_helper_methods_to_document = registry .get("ViewComponent::TestHelpers") .meths diff --git a/lib/view_component.rb b/lib/view_component.rb index 62c9cd2cb..5f1123cc6 100644 --- a/lib/view_component.rb +++ b/lib/view_component.rb @@ -11,7 +11,7 @@ module ViewComponent autoload :Compiler autoload :CompileCache autoload :ComponentError - autoload :Config + autoload :GlobalConfig autoload :Deprecation autoload :InlineTemplate autoload :Instrumentation diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index 905bdf13e..67dfaaa0a 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -5,7 +5,7 @@ require "view_component/collection" require "view_component/compile_cache" require "view_component/compiler" -require "view_component/config" +require "view_component/global_config" require "view_component/errors" require "view_component/inline_template" require "view_component/preview" @@ -18,13 +18,13 @@ module ViewComponent class Base < ActionView::Base class << self - delegate(*ViewComponent::Config.defaults.keys, to: :config) + delegate(*ViewComponent::GlobalConfig.defaults.keys, to: :config) # Returns the current config. # # @return [ActiveSupport::OrderedOptions] def config - ViewComponent::Config.current + ViewComponent::GlobalConfig.current end end diff --git a/lib/view_component/engine.rb b/lib/view_component/engine.rb index 8932ad800..b48c2840c 100644 --- a/lib/view_component/engine.rb +++ b/lib/view_component/engine.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true require "rails" -require "view_component/config" +require "view_component/global_config" require "view_component/deprecation" module ViewComponent class Engine < Rails::Engine # :nodoc: - config.view_component = ViewComponent::Config.current + config.view_component = ViewComponent::GlobalConfig.current rake_tasks do load "view_component/rails/tasks/view_component.rake" diff --git a/lib/view_component/config.rb b/lib/view_component/global_config.rb similarity index 97% rename from lib/view_component/config.rb rename to lib/view_component/global_config.rb index 85e119faf..8eea1b585 100644 --- a/lib/view_component/config.rb +++ b/lib/view_component/global_config.rb @@ -3,7 +3,7 @@ require "view_component/deprecation" module ViewComponent - class Config + class GlobalConfig class << self # `new` without any arguments initializes the default configuration, but # it's important to differentiate in case that's no longer the case in @@ -181,10 +181,10 @@ def default_generate_options end # @!attribute current - # @return [ViewComponent::Config] - # Returns the current ViewComponent::Config. This is persisted against this + # @return [ViewComponent::GlobalConfig] + # Returns the current ViewComponent::GlobalConfig. This is persisted against this # class so that config options remain accessible before the rest of - # ViewComponent has loaded. Defaults to an instance of ViewComponent::Config + # ViewComponent has loaded. Defaults to an instance of ViewComponent::GlobalConfig # with all other documented defaults set. class_attribute :current, default: defaults, instance_predicate: false diff --git a/test/sandbox/test/config_test.rb b/test/sandbox/test/config_test.rb index 86c662a02..e4fc2ded0 100644 --- a/test/sandbox/test/config_test.rb +++ b/test/sandbox/test/config_test.rb @@ -5,7 +5,7 @@ module ViewComponent class ConfigTest < TestCase def setup - @config = ViewComponent::Config.new + @config = ViewComponent::GlobalConfig.new end def test_defaults_are_correct @@ -29,9 +29,9 @@ def test_all_methods_are_documented Rake::Task["yard"].execute configuration_methods_to_document = YARD::RegistryStore.new.tap do |store| store.load!(".yardoc") - end.get("ViewComponent::Config").meths.select(&:reader?).reject { |meth| meth.name == :config } - default_options = ViewComponent::Config.defaults.keys - accessors = ViewComponent::Config.instance_methods(false).reject do |method_name| + end.get("ViewComponent::GlobalConfig").meths.select(&:reader?).reject { |meth| meth.name == :config } + default_options = ViewComponent::GlobalConfig.defaults.keys + accessors = ViewComponent::GlobalConfig.instance_methods(false).reject do |method_name| method_name.to_s.end_with?("=") || method_name == :method_missing end options_defined_on_instance = Set[*default_options, *accessors]