packs-rails 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c9a4e816b8efb6891cf9b373c7c099b28a3d2f17d4f240d1177182698e1e791
|
4
|
+
data.tar.gz: 9e1428992751e466c6cefb19230c1b0e5f0bad323b5740951e18e5e3e68604ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7400fe1e63caf68bc2ade9b562f9ebc5562bc661bd6a31093356a17a46161610e4807df6aa0d8bb10318e13420fd75fff628dfe70b5312e0241e343bdd96d15
|
7
|
+
data.tar.gz: a329905ac9d4aa3de0d6b650d3acca0c7c917ef615de2c439ba61f440b4d33e998f5c5c0c6257ac165df060e5df16c8c46f6d1658211cc18b3dd9f227c272d16
|
data/README.md
CHANGED
@@ -23,7 +23,7 @@ packs/
|
|
23
23
|
models/ # Private models
|
24
24
|
some_other_non_namespaced_private_model.rb # this works too
|
25
25
|
my_domain/
|
26
|
-
|
26
|
+
my_private_namespaced_model.rb
|
27
27
|
controllers/
|
28
28
|
views/
|
29
29
|
config/
|
@@ -53,21 +53,23 @@ packs/
|
|
53
53
|
|
54
54
|
## Usage
|
55
55
|
|
56
|
-
Setting up `packs-rails` is straightforward. Simply by including `packs-rails` in your `Gemfile` in all environments
|
56
|
+
Setting up `packs-rails` is straightforward. Simply by including `packs-rails` in your `Gemfile` in **all environments**, `packs-rails` will automatically hook into and configure Rails.
|
57
57
|
|
58
58
|
From there, you can create a `./packs` folder and structure it using the conventions listed above.
|
59
59
|
|
60
60
|
If you wish to use a different directory name, eg `components` instead of `packs`, you can customize this by configuring `packs.yml`. See [`packs`](https://github.com/rubyatscale/packs) for more information.
|
61
61
|
|
62
62
|
### Splitting routes
|
63
|
-
`packs-rails` allows you to split your application routes for every pack. You just have to create a file describing your routes and then `draw` them in your root `config/routes.rb` file.
|
63
|
+
`packs-rails` allows you to split your application routes for every pack. You just have to create a file describing your routes and then `draw` them in your root `config/routes.rb` file (NOTE: the `draw` function is only in Rails 6.1+).
|
64
64
|
|
65
65
|
```ruby
|
66
66
|
# packs/my_domain/config/routes/my_domain.rb
|
67
67
|
resources :my_resource
|
68
68
|
|
69
69
|
# config/routes.rb
|
70
|
-
draw
|
70
|
+
Rails.application.routes.draw do
|
71
|
+
draw(:my_domain)
|
72
|
+
end
|
71
73
|
```
|
72
74
|
|
73
75
|
### Making your Package an Engine
|
@@ -80,6 +82,18 @@ metadata:
|
|
80
82
|
engine: true
|
81
83
|
```
|
82
84
|
|
85
|
+
Add `engine_name: ` to your `package.yml` to use a specific, maybe namespaced, engine name instead of the last package folder name.
|
86
|
+
```yml
|
87
|
+
# packs/my_pack/package.yml
|
88
|
+
enforce_dependencies: true
|
89
|
+
enforce_privacy: true
|
90
|
+
metadata:
|
91
|
+
engine: true
|
92
|
+
engine_name: namespaced/my_pack
|
93
|
+
```
|
94
|
+
|
95
|
+
The engine is created as `Namespaced::MyPack::Engine` instead of `MyPack::Engine`.
|
96
|
+
|
83
97
|
## Ecosystem and Integrations
|
84
98
|
|
85
99
|
### RSpec Integration
|
@@ -9,6 +9,7 @@ module Packs
|
|
9
9
|
|
10
10
|
Packs.all.reject(&:is_gem?).each do |pack|
|
11
11
|
app.config.factory_bot.definition_file_paths << pack.relative_path.join("spec/factories").to_s
|
12
|
+
app.config.factory_bot.definition_file_paths << pack.relative_path.join("test/factories").to_s
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -7,6 +7,8 @@ module Packs
|
|
7
7
|
module Rails
|
8
8
|
module Integrations
|
9
9
|
class Rails
|
10
|
+
CONFIG_ROUTES_PATH = "config/routes".freeze
|
11
|
+
|
10
12
|
def initialize(app)
|
11
13
|
@app = app
|
12
14
|
|
@@ -27,6 +29,10 @@ module Packs
|
|
27
29
|
def inject_paths
|
28
30
|
Packs.all.reject(&:is_gem?).each do |pack|
|
29
31
|
Packs::Rails.config.paths.each do |path|
|
32
|
+
# Prior to Rails 6.1, the "config/routes" app path is nil and was not added until drawable routes feature was implemented
|
33
|
+
# https://github.com/rails/rails/pull/37892/files#diff-a785e41df3f87063a8fcffcac726856a25d8eae6d1f9bca2b36989fe88613f8eR62
|
34
|
+
next if pre_rails_6_1? && path == CONFIG_ROUTES_PATH
|
35
|
+
|
30
36
|
@app.paths[path] << pack.relative_path.join(path)
|
31
37
|
end
|
32
38
|
end
|
@@ -34,6 +40,11 @@ module Packs
|
|
34
40
|
|
35
41
|
private
|
36
42
|
|
43
|
+
def pre_rails_6_1?
|
44
|
+
return @_pre_rails_6_1 if defined?(@_pre_rails_6_1)
|
45
|
+
@_pre_rails_6_1 = ::Rails.gem_version < Gem::Version.new("6.1")
|
46
|
+
end
|
47
|
+
|
37
48
|
def create_namespace(name)
|
38
49
|
namespace = ActiveSupport::Inflector.camelize(name)
|
39
50
|
namespace.split("::").reduce(Object) do |base, mod|
|
@@ -46,7 +57,7 @@ module Packs
|
|
46
57
|
end
|
47
58
|
|
48
59
|
def create_engine(pack)
|
49
|
-
name = pack.last_name
|
60
|
+
name = pack.metadata.fetch("engine_name", pack.last_name)
|
50
61
|
namespace = create_namespace(name)
|
51
62
|
stim = Stim.new(pack, namespace)
|
52
63
|
namespace.const_set("Engine", Class.new(::Rails::Engine)).include(stim)
|
data/lib/packs/rails/railtie.rb
CHANGED
@@ -5,12 +5,15 @@ module Packs
|
|
5
5
|
class Railtie < ::Rails::Railtie
|
6
6
|
config.before_configuration do |app|
|
7
7
|
Integrations::Rails.new(app)
|
8
|
-
|
9
|
-
|
8
|
+
|
10
9
|
# This is not used within packs-rails. Rather, this allows OTHER tools to
|
11
10
|
# hook into packs-rails via ActiveSupport hooks.
|
12
11
|
ActiveSupport.run_load_hooks(:packs_rails, Packs)
|
13
12
|
end
|
13
|
+
|
14
|
+
config.after_initialize do |app|
|
15
|
+
Integrations::FactoryBot.new(app)
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
data/lib/packs/rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ngan Pham
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|