Skip to content

Commit

Permalink
Use Packs specification
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Evanczuk committed Dec 21, 2022
1 parent 653637b commit 480c676
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 117 deletions.
4 changes: 2 additions & 2 deletions lib/stimpack.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'packs'
require "active_support"
require "rails/application"
require 'sorbet-runtime'

module Stimpack
extend ActiveSupport::Autoload

autoload :Integrations
autoload :Pack
autoload :Packs
autoload :Railtie
autoload :Stim

Expand Down
2 changes: 2 additions & 0 deletions lib/stimpack/integrations/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# typed: true

module Stimpack
module Integrations
class FactoryBot
Expand Down
13 changes: 8 additions & 5 deletions lib/stimpack/integrations/rails.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
# typed: true

require "active_support/inflections"

Expand All @@ -14,17 +15,19 @@ def initialize(app)
end

def create_engines
Packs.configure { |config| config.roots = [Stimpack.config.root] }

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

pack.engine = create_engine(pack)
create_engine(pack)
end
end

def inject_paths
Packs.all.each do |pack|
Stimpack.config.paths.each do |path|
@app.paths[path] << pack.path.join(path)
@app.paths[path] << pack.relative_path.join(path)
end
end
end
Expand All @@ -43,8 +46,8 @@ def create_namespace(name)
end

def create_engine(pack)
name = pack.path.relative_path_from(Stimpack::Packs.root)
namespace = create_namespace(pack.name)
name = pack.last_name
namespace = create_namespace(name)
stim = Stim.new(pack, namespace)
namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
end
Expand Down
16 changes: 14 additions & 2 deletions lib/stimpack/integrations/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# typed: true

module Stimpack
module Integrations
class RSpec
extend T::Sig

def initialize
# This is the list of directories RSpec was told to run.
to_run = ::RSpec.configuration.instance_variable_get(:@files_or_directories_to_run)
Expand All @@ -10,6 +14,7 @@ def initialize
# 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 = [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 All @@ -26,10 +31,10 @@ def initialize
# If it doesn't match a pack path, we leave it alone.

to_run.map! do |path|
if pack = Packs.all_by_path[path]
if pack = Packs.find(path)
[
pack,
*Packs.all(pack)
*nested_packs_for(pack)
].map do |pack|
spec_path = pack.relative_path.join(default_path)
spec_path.to_s if spec_path.exist?
Expand All @@ -42,6 +47,13 @@ def initialize

::RSpec.configuration.files_or_directories_to_run = to_run.flatten.compact.uniq
end

sig { params(parent_pack: Packs::Pack).returns(T::Array[Packs::Pack]) }
def nested_packs_for(parent_pack)
Packs.all.select do |pack|
pack.name != parent_pack.name && pack.name.include?(parent_pack.name)
end
end
end
end
end
28 changes: 0 additions & 28 deletions lib/stimpack/pack.rb

This file was deleted.

30 changes: 0 additions & 30 deletions lib/stimpack/pack/configuration.rb

This file was deleted.

48 changes: 0 additions & 48 deletions lib/stimpack/packs.rb

This file was deleted.

9 changes: 7 additions & 2 deletions lib/stimpack/stim.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# typed: true

module Stimpack
class Stim < Module
extend T::Sig

sig { params(pack: Packs::Pack, namespace: Module).void }
def initialize(pack, namespace)
@pack = pack
@namespace = namespace
super()
end

def included(engine)
engine.called_from = @pack.path
engine.called_from = @pack.relative_path
engine.extend(ClassMethods)
engine.isolate_namespace(@namespace)

Expand All @@ -28,7 +33,7 @@ def included(engine)

module ClassMethods
def find_root(_from)
called_from
T.unsafe(self).called_from
end
end
end
Expand Down
80 changes: 80 additions & 0 deletions sorbet/rbi/gems/packs@0.0.2.rbi

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

1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "bundler/setup"
require "stimpack"
require 'pry'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
1 change: 1 addition & 0 deletions stimpack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "railties"
spec.add_dependency "activesupport"
spec.add_dependency "packs"

spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
Expand Down

0 comments on commit 480c676

Please sign in to comment.