Skip to content

Commit

Permalink
Allow packs configuration to be set in one place (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Evanczuk authored Dec 29, 2022
1 parent 1176753 commit dc11fdb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
17 changes: 17 additions & 0 deletions lib/stimpack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ class << self
def root
@root ||= Rails::Application.find_root(Dir.pwd)
end

#
# This is temporary. For now, we allow Stimpack roots to be configured via Stimpack.config.root
# Later, if clients configure packs directly, we can deprecate the Stimpack setting and
# remove this function and its invocations.
#
def configure_packs
Packs.configure do |config|
roots = Array(Stimpack.config.root)
pack_paths = roots.flat_map do |root|
# Support nested packs by default. Later, this can be pushed to a client configuration.
["#{root}/*", "#{root}/*/*"]
end

config.pack_paths = pack_paths
end
end
end

@config = ActiveSupport::OrderedOptions.new
Expand Down
2 changes: 2 additions & 0 deletions lib/stimpack/integrations/factory_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ module Integrations
class FactoryBot
def initialize(app)
return unless app.config.respond_to?(:factory_bot)
Stimpack.configure_packs

Packs.all.each do |pack|
next if pack.relative_path.glob('*.gemspec').any?
app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/stimpack/integrations/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ def initialize(app)
@app = app

Stimpack.config.paths.freeze
Stimpack.configure_packs

create_engines
inject_paths
end

def create_engines
# Ideally, the user just does `Packs.configure { |config| config.roots = '...' }`
# But that would be a public API change and can come later
Packs.configure { |config| config.roots = Array(Stimpack.config.root) }

Packs.all.each do |pack|
next unless pack.metadata['engine']

Expand Down
3 changes: 2 additions & 1 deletion lib/stimpack/integrations/rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ def initialize
to_run = ::RSpec.configuration.instance_variable_get(:@files_or_directories_to_run)
default_path = ::RSpec.configuration.default_path

Stimpack.configure_packs

if to_run == [default_path]
# This is the default case when you run `rspec`. We want to add all the pack's spec paths
# to the collection of directories to run.

Packs.configure { |config| config.roots = Array(Stimpack.config.root) }
pack_paths = Packs.all.map do |pack|
spec_path = pack.relative_path.join(default_path)
spec_path.to_s if spec_path.exist?
Expand Down
2 changes: 1 addition & 1 deletion lib/stimpack/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Stimpack
VERSION = "0.8.1".freeze
VERSION = "0.8.2".freeze
end
32 changes: 18 additions & 14 deletions sorbet/rbi/gems/packs@0.0.2.rbi → sorbet/rbi/gems/packs@0.0.4.rbi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc11fdb

Please sign in to comment.