diff --git a/draper.gemspec b/draper.gemspec index 75ff6f8..865ed49 100644 --- a/draper.gemspec +++ b/draper.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency "rails", ">= 6.1" s.add_runtime_dependency "request_store", ">= 1.0" + s.add_runtime_dependency "zeitwerk" s.add_development_dependency "appraisal" s.add_development_dependency "capybara" diff --git a/lib/draper.rb b/lib/draper.rb index 2e3eb2b..b68255a 100644 --- a/lib/draper.rb +++ b/lib/draper.rb @@ -3,9 +3,11 @@ require "active_support/concern" require "request_store" -require "draper/view_context" -require "draper/decorator" -require "draper/version" +require 'zeitwerk' +loader = Zeitwerk::Loader.for_gem +loader.ignore("#{__dir__}/rails") +loader.ignore("#{__dir__}/test") +loader.setup module Draper require "draper/engine" if defined?(Rails) diff --git a/lib/draper/engine.rb b/lib/draper/engine.rb index bdd6a98..69e8773 100644 --- a/lib/draper/engine.rb +++ b/lib/draper/engine.rb @@ -17,7 +17,17 @@ class Engine < ::Rails::Engine end config.after_initialize do |_app| - require "draper/test/rspec_integration" if Rails.env.test? && defined?(RSpec) && RSpec.respond_to?(:configure) + if Rails.env.test? && defined?(RSpec) && RSpec.respond_to?(:configure) + require "draper/test/rspec_integration" + + RSpec.configure do |config| + config.include DecoratorExampleGroup, file_path: %r{spec/decorators}, type: :decorator + + %i[decorator controller mailer].each do |type| + config.before(:each, type: type) { Draper::ViewContext.clear! } + end + end + end end rake_tasks do diff --git a/lib/draper/test/rspec_integration.rb b/lib/draper/test/rspec_integration.rb index 0147a69..4d8474a 100644 --- a/lib/draper/test/rspec_integration.rb +++ b/lib/draper/test/rspec_integration.rb @@ -6,12 +6,4 @@ module DecoratorExampleGroup included { metadata[:type] = :decorator } end - - RSpec.configure do |config| - config.include DecoratorExampleGroup, file_path: %r{spec/decorators}, type: :decorator - - %i[decorator controller mailer].each do |type| - config.before(:each, type: type) { Draper::ViewContext.clear! } - end - end end diff --git a/lib/draper/view_context.rb b/lib/draper/view_context.rb index a5ae5fb..c0d516c 100644 --- a/lib/draper/view_context.rb +++ b/lib/draper/view_context.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -require "draper/view_context/build_strategy" -require "draper/view_context/base_helper" -require "draper/view_context/controller_helper" - module Draper module ViewContext module_function