Skip to content

Commit

Permalink
Added possibility to set custom engine name (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfsw authored and shageman committed Dec 5, 2023
1 parent ab62d6b commit fc6eccd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
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

0 comments on commit fc6eccd

Please sign in to comment.