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 } instance_methods_to_document = meths.select { |method| method.scope != :class }
class_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 test_helper_methods_to_document = registry
.get("ViewComponent::TestHelpers") .get("ViewComponent::TestHelpers")
.meths .meths

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

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

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

@ -5,7 +5,7 @@ require "active_support/configurable"
require "view_component/collection" require "view_component/collection"
require "view_component/compile_cache" require "view_component/compile_cache"
require "view_component/compiler" require "view_component/compiler"
require "view_component/config" require "view_component/global_config"
require "view_component/errors" require "view_component/errors"
require "view_component/inline_template" require "view_component/inline_template"
require "view_component/preview" require "view_component/preview"
@ -18,13 +18,13 @@ require "view_component/use_helpers"
module ViewComponent module ViewComponent
class Base < ActionView::Base class Base < ActionView::Base
class << self class << self
delegate(*ViewComponent::Config.defaults.keys, to: :config) delegate(*ViewComponent::GlobalConfig.defaults.keys, to: :config)
# Returns the current config. # Returns the current config.
# #
# @return [ActiveSupport::OrderedOptions] # @return [ActiveSupport::OrderedOptions]
def config def config
ViewComponent::Config.current ViewComponent::GlobalConfig.current
end end
end end

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

@ -1,12 +1,12 @@
# frozen_string_literal: true # frozen_string_literal: true
require "rails" require "rails"
require "view_component/config" require "view_component/global_config"
require "view_component/deprecation" require "view_component/deprecation"
module ViewComponent module ViewComponent
class Engine < Rails::Engine # :nodoc: class Engine < Rails::Engine # :nodoc:
config.view_component = ViewComponent::Config.current config.view_component = ViewComponent::GlobalConfig.current
rake_tasks do rake_tasks do
load "view_component/rails/tasks/view_component.rake" load "view_component/rails/tasks/view_component.rake"

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

@ -3,7 +3,7 @@
require "view_component/deprecation" require "view_component/deprecation"
module ViewComponent module ViewComponent
class Config class GlobalConfig
class << self class << self
# `new` without any arguments initializes the default configuration, but # `new` without any arguments initializes the default configuration, but
# it's important to differentiate in case that's no longer the case in # it's important to differentiate in case that's no longer the case in
@ -181,10 +181,10 @@ module ViewComponent
end end
# @!attribute current # @!attribute current
# @return [ViewComponent::Config] # @return [ViewComponent::GlobalConfig]
# Returns the current ViewComponent::Config. This is persisted against this # Returns the current ViewComponent::GlobalConfig. This is persisted against this
# class so that config options remain accessible before the rest of # 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. # with all other documented defaults set.
class_attribute :current, default: defaults, instance_predicate: false class_attribute :current, default: defaults, instance_predicate: false

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

@ -5,7 +5,7 @@ require "test_helper"
module ViewComponent module ViewComponent
class ConfigTest < TestCase class ConfigTest < TestCase
def setup def setup
@config = ViewComponent::Config.new @config = ViewComponent::GlobalConfig.new
end end
def test_defaults_are_correct def test_defaults_are_correct
@ -29,9 +29,9 @@ module ViewComponent
Rake::Task["yard"].execute Rake::Task["yard"].execute
configuration_methods_to_document = YARD::RegistryStore.new.tap do |store| configuration_methods_to_document = YARD::RegistryStore.new.tap do |store|
store.load!(".yardoc") store.load!(".yardoc")
end.get("ViewComponent::Config").meths.select(&:reader?).reject { |meth| meth.name == :config } end.get("ViewComponent::GlobalConfig").meths.select(&:reader?).reject { |meth| meth.name == :config }
default_options = ViewComponent::Config.defaults.keys default_options = ViewComponent::GlobalConfig.defaults.keys
accessors = ViewComponent::Config.instance_methods(false).reject do |method_name| accessors = ViewComponent::GlobalConfig.instance_methods(false).reject do |method_name|
method_name.to_s.end_with?("=") || method_name == :method_missing method_name.to_s.end_with?("=") || method_name == :method_missing
end end
options_defined_on_instance = Set[*default_options, *accessors] options_defined_on_instance = Set[*default_options, *accessors]