Skip to content

Commit

Permalink
Switch to zeitwerk to load gem
Browse files Browse the repository at this point in the history
  • Loading branch information
n-rodriguez committed Jan 28, 2024
1 parent d96c67d commit 38144c7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions draper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions lib/draper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion lib/draper/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/draper/test/rspec_integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions lib/draper/view_context.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 38144c7

Please sign in to comment.