packs-rails 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -5
- data/lib/packs/rails/integrations/factory_bot.rb +1 -0
- data/lib/packs/rails/integrations/rails.rb +12 -1
- data/lib/packs/rails/railtie.rb +1 -0
- data/lib/packs/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4b16ad1fd38eabdd5c57a587cf893991dc3d67a84bc0111f04e647d67878b63
|
4
|
+
data.tar.gz: bfaaaee8ef07fd9dbf5f7056133c18f294095a3db369cc56d10ffa0f8c0edd0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 424e39b8c152ee19afb8b85ac5a393145bef1315a7a88acf3fd55bf18033503d4a817313543d397c3b2210013de9aa765a1831f63ee4ffa8a6e5c45e95653e03
|
7
|
+
data.tar.gz: f99f87275c735db75b54dac68001fb3dedef117906b7cd20e6b392df96d200348961e69591fb8979784e855f39526a3cabe372f5626f73d95e5bc8b7b823d4cf
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ app/ # Unpackaged code
|
|
11
11
|
packs/
|
12
12
|
my_domain/
|
13
13
|
package.yml # See the packwerk docs for more info
|
14
|
-
|
14
|
+
package_todo.yml # See the packwerk docs for more info
|
15
15
|
app/
|
16
16
|
public/ # Recommended location for public API
|
17
17
|
my_domain.rb # creates the primary namespaces
|
@@ -42,7 +42,7 @@ packs/
|
|
42
42
|
some_other_non_namespaced_private_model_spec.rb
|
43
43
|
my_domain/
|
44
44
|
my_private_namespaced_model_spec.rb
|
45
|
-
factories/ # packs-rails will automatically load pack factories into FactoryBot
|
45
|
+
factories/ # packs-rails will automatically load pack factories into FactoryBot, see Ecosystem and Integrations#factory_bot below
|
46
46
|
my_domain/
|
47
47
|
my_private_namespaced_model_factory.rb
|
48
48
|
my_other_domain/
|
@@ -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
|
@@ -111,6 +125,31 @@ rspec packs/foobar/spec
|
|
111
125
|
rspec packs/foobar/nested_pack
|
112
126
|
```
|
113
127
|
|
128
|
+
#### factory_bot and factory_bot_rails
|
129
|
+
|
130
|
+
Ensure you have the gem in your Gemfile, and that `require: false` is not present, otherwise the `packs-rails` FactoryBot integration will not be run upon application/environment load.
|
131
|
+
This integration will automatically add the `[spec|test]/factories` directory from each pack to the application's `config.factory_bot.definition_file_paths`.
|
132
|
+
|
133
|
+
Using the example application above:
|
134
|
+
```
|
135
|
+
...
|
136
|
+
packs/
|
137
|
+
my_domain/
|
138
|
+
...
|
139
|
+
spec/ # OR test/
|
140
|
+
...
|
141
|
+
factories/
|
142
|
+
my_domain/
|
143
|
+
my_private_namespaced_model_factory.rb
|
144
|
+
my_other_domain/
|
145
|
+
...
|
146
|
+
spec/ # OR test/
|
147
|
+
...
|
148
|
+
factories/
|
149
|
+
my_other_domain/
|
150
|
+
my_private_namespaced_model_factory.rb
|
151
|
+
```
|
152
|
+
|
114
153
|
#### parallel_tests
|
115
154
|
|
116
155
|
`parallel_tests` has it its own spec discovery mechanism, so packs-rails's RSpec integration doesn't do anything when you use them together.
|
@@ -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
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.5
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|