Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to set custom engine name #65

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ metadata:
engine: true
```

Add `engine_name: ` to your `package.yml` to use a specific, maybe namespaced, engine name instead of the last package folder name.
```yml
# packs/my_pack/package.yml
enforce_dependencies: true
enforce_privacy: true
metadata:
engine: true
engine_name: namespaced/my_pack
```

The engine is created as `Namespaced::MyPack::Engine` instead of `MyPack::Engine`.

## Ecosystem and Integrations

### RSpec Integration
Expand Down
2 changes: 1 addition & 1 deletion lib/packs/rails/integrations/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_namespace(name)
end

def create_engine(pack)
name = pack.last_name
name = pack.metadata.fetch("engine_name", pack.last_name)
namespace = create_namespace(name)
stim = Stim.new(pack, namespace)
namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Pants
module Jeans
class Bootcut
end
end
end
3 changes: 3 additions & 0 deletions spec/fixtures/rails-7.0/packs/pants/jeans/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
metadata:
engine: true
engine_name: pants/jeans
16 changes: 16 additions & 0 deletions spec/packs-rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@
end
end

context 'custom engine name' do
it "autoloads classes in autoload paths" do
expect(defined?(Pants::Jeans::Bootcut)).to eq("constant")
end

it "adds pack paths to the application" do
Packs::Rails.config.paths.each do |path|
expect(Rails.application.paths[path].paths).to include(rails_dir.join('packs', "pants", "jeans", path))
end
end

it "creates engines namespace for engine packs" do
expect(defined?(Pants::Jeans::Engine)).to eq("constant")
end
end

context 'alternate roots' do
it "autoloads classes in autoload paths" do
expect(defined?(Belts::Brown)).to eq("constant")
Expand Down