Skip to content

Commit 99ba721

Browse files
authored
Merge pull request #224 from hlascelles/add-engine-configurer
Add Rails Engine helper
2 parents 3617a12 + fa0ca70 commit 99ba721

File tree

13 files changed

+63
-15
lines changed

13 files changed

+63
-15
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.0 (2025-07-16)
2+
3+
- Add Rails Engine helper [#224](https://github.com/hlascelles/figjam/pull/224)
4+
15
## 2.1.0 (2025-07-15)
26

37
- Raise exception if config path is invalid [#223](https://github.com/hlascelles/figjam/pull/223)

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
figjam (2.1.0)
4+
figjam (2.2.0)
55
thor (>= 0.14.0, < 2)
66

77
GEM

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,26 @@ overrides.
5959

6060
Figjam is perfect for Rails engines. They can have their own configuration file, and
6161
they can be loaded independently or in addition of the main application. To do this,
62-
you can create a `config/application.yml` file in your engine, and add this initializer:
62+
you can create a `config/application.yml` file in your engine, and add this to the `Rails::Engine`:
6363

6464
```ruby
65-
Figjam::Application.new(
66-
environment: ::Rails.env,
67-
path: File.expand_path("../application.yml", __dir__)
68-
).load
65+
module MyEngine
66+
class Engine < ::Rails::Engine
67+
Figjam::Rails::Engine.configure(self)
68+
end
69+
end
70+
71+
# Or if you wish to pass in a specific value for the environment:
72+
module MyEngine
73+
class Engine < ::Rails::Engine
74+
Figjam::Rails::Engine.configure(self, "my_engine_environment")
75+
end
76+
end
6977
```
7078

79+
This will ensure that the engine's configuration is loaded when the Rails application starts, and
80+
before any other initializers run.
81+
7182
### Usage without Rails
7283

7384
If you are not using Rails, you can load Figjam in your gem. Note, you can

config/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{} # Needed for testing the gem
1+
{}

gemfiles/psych_4.0.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
figjam (2.1.0)
4+
figjam (2.2.0)
55
thor (>= 0.14.0, < 2)
66

77
GEM

gemfiles/psych_5.0.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
figjam (2.1.0)
4+
figjam (2.2.0)
55
thor (>= 0.14.0, < 2)
66

77
GEM

gemfiles/rails_7.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
figjam (2.1.0)
4+
figjam (2.2.0)
55
thor (>= 0.14.0, < 2)
66

77
GEM

gemfiles/rails_8.gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
figjam (2.1.0)
4+
figjam (2.2.0)
55
thor (>= 0.14.0, < 2)
66

77
GEM

lib/figjam/rails.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Cater for no Rails
77
else
88
require "figjam/rails/application"
9+
require "figjam/rails/engine"
910

1011
Figjam.adapter = Figjam::Rails::Application
1112
require "figjam/rails/railtie"

lib/figjam/rails/engine.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Figjam
2+
module Rails
3+
module Engine
4+
class << self
5+
def configure(engine_context, environment = ::Rails.env)
6+
engine_context.config.before_configuration do
7+
Figjam::Application.new(
8+
environment: environment,
9+
path: "#{engine_context.root}/config/application.yml"
10+
).load
11+
end
12+
end
13+
end
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)