diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2029fa4f3..cae2fe1cf 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 6 ## main +* Resolve deprecation warning for `ActiveSupport::Configurable`. + + *Simon Fish* + * Make `ViewComponent::VERSION` accessible to other gems by default. *Hans Lemuet* diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index 97ba41815..8f8619c67 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "action_view" -require "active_support/configurable" require "view_component/collection" require "view_component/compile_cache" require "view_component/compiler" diff --git a/lib/view_component/configurable.rb b/lib/view_component/configurable.rb index b878a7ab3..1e92c7473 100644 --- a/lib/view_component/configurable.rb +++ b/lib/view_component/configurable.rb @@ -4,14 +4,30 @@ module ViewComponent module Configurable extend ActiveSupport::Concern + class_methods do + def config + @_config ||= if respond_to?(:superclass) && superclass.respond_to?(:config) + superclass.config.inheritable_copy + else + ActiveSupport::OrderedOptions.new + end + end + + def configure + yield config + end + end + included do next if respond_to?(:config) && config.respond_to?(:view_component) && config.respond_to_missing?(:instrumentation_enabled) - include ActiveSupport::Configurable - configure do |config| config.view_component ||= ActiveSupport::InheritableOptions.new end + + def config + self.class.config + end end end end