This commit is contained in:
Simon Fish 2024-08-03 09:40:22 +01:00
Родитель 3bc2fca15c
Коммит cd9c4579a8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 37A56BC36AB4C031
6 изменённых файлов: 15 добавлений и 15 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -11,7 +11,7 @@ module ViewComponent
autoload :Compiler
autoload :CompileCache
autoload :ComponentError
autoload :Config
autoload :GlobalConfig
autoload :Deprecation
autoload :InlineTemplate
autoload :Instrumentation

Просмотреть файл

@ -5,7 +5,7 @@ require "active_support/configurable"
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 @@ require "view_component/use_helpers"
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

Просмотреть файл

@ -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"

Просмотреть файл

@ -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 @@ module ViewComponent
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

Просмотреть файл

@ -5,7 +5,7 @@ require "test_helper"
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 @@ module ViewComponent
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]