Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module ViewComponent
autoload :Compiler
autoload :CompileCache
autoload :ComponentError
autoload :Config
autoload :GlobalConfig
autoload :Deprecation
autoload :InlineTemplate
autoload :Instrumentation
Expand Down
6 changes: 3 additions & 3 deletions lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/view_component/engine.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions test/sandbox/test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down