automatic_namespaces 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eabe8d9d26c2bf99b74b99a047bfb6445eee106a7437571c7062cc163f9f13bf
4
- data.tar.gz: 21153b5fe8d5ce982f70964970ad448d75974506435ab67a49f03e881609cb3a
3
+ metadata.gz: e7aa390b64ae64d8c78d9b6ac2af5bd2e98d0c63007220eccba244f90ed3c674
4
+ data.tar.gz: 9acd543871604473d1ac25ca14d64e48873c18c7265ea4c9641def935737ecb4
5
5
  SHA512:
6
- metadata.gz: 6e9e6b77583f244650d94c09cf20d41fd8d1b6ec8ed1f95dd9f6345cfef05e588700b03ca8dad75c5b0ebf0cd12328ef1d75f0a975524cb4874face90a3e03c1
7
- data.tar.gz: 2e19e2aacb6dd786ac9aacc14cfebd9a0104f5e3fcd5e66dc8916f98c917321911ead978f822ae350ec5dbb054455c6d8a363515f3176198200f36e8d335e686
6
+ metadata.gz: 0b2c495a8cd14320988c3ee06a760f913611f1e2f5cf82d14ec0ba01d276b85bd00a8d404b1d6bed6e37a1a0ba454a76a1bfda15327fb445798751d03fef425d
7
+ data.tar.gz: df329e6def590f4714ef782ab235d82a89daee0fbf2cf3291527e1bd3cf719f24e7bb75981c40d659db98dc31140e3f4732b867eccf888d3daf6a966e06a51e4
data/README.md CHANGED
@@ -11,7 +11,7 @@ app
11
11
  │ │ ├── class1.rb # contains Component1::Class1
12
12
  ```
13
13
 
14
- When building a modular monolith using packages ([packwerk](https://github.com/Shopify/packwerk) + [stimpack](https://github.com/rubyatscale/stimpack)),
14
+ When building a modular monolith using packages ([packwerk](https://github.com/Shopify/packwerk) + [packs-rails](https://github.com/rubyatscale/packs-rails)),
15
15
  this pattern creates a lot of extra noise in the directory structure:
16
16
 
17
17
  ```
@@ -40,7 +40,7 @@ And that's only for a single pack! As your modular monolith grows, you'll likely
40
40
  hundreds) of packs. That's a lot of "namespace" directories that aren't adding a lot of value. You already
41
41
  know the namespace of those classes in a strongly namespaced pack -- it's the pack name -- can Zeitwerk know it, too?
42
42
 
43
- This gem patches the Rails 7 autoloader so that most subdirectories under your strongly namespaced component's `app` directory are
43
+ This gem configures the Rails 7 autoloader so that most subdirectories under your strongly namespaced component's `app` directory are
44
44
  automatically associated with the namespace.
45
45
 
46
46
  ## Installation
@@ -57,7 +57,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
57
57
 
58
58
  Given the `package.yml` of a strongly namespaced pack:
59
59
 
60
- ```
60
+ ```yml
61
61
  enforce_dependencies: true
62
62
  enforce_privacy: true
63
63
  public_path: app/public/
@@ -72,7 +72,7 @@ metadata:
72
72
 
73
73
  modify the metadata to opt into automatic namespacing:
74
74
 
75
- ```
75
+ ```yml
76
76
  metadata:
77
77
  automatic_pack_namespace: true
78
78
  ```
@@ -99,7 +99,7 @@ metadata:
99
99
  If your package / namespace name requires ActiveSupport inflections, you will probably need to tell `automatic_namespaces`
100
100
  what the correct namespace name should be in that package:
101
101
 
102
- ```
102
+ ```yml
103
103
  # packs/shoes_ui/package.yml
104
104
  metadata:
105
105
  automatic_pack_namespace: true
@@ -109,9 +109,19 @@ metadata:
109
109
  This is necessary because `automatic_namespaces` works by modifying the autoloader paths, which has to
110
110
  happen during Rails application initialization; but the inflector is not available for use then.
111
111
 
112
+ If you would like to use your own file layout conventions for packs (i.e. not `app/*`) you can specify
113
+ your own glob by using `autoload_glob` to append the glob to the folder containing package.yml. This defaults
114
+ to `'/**/app/*'`
115
+
116
+ ```yml
117
+ metadata:
118
+ # Put the folder containing package.yml as the root for the autoloader.
119
+ autoload_glob: ''
120
+ ```
121
+
112
122
  ## Development
113
123
 
114
- After checking out the repo, run `bundle instal` to install dependencies. Then, run `rspec` to run the tests.
124
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
115
125
 
116
126
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
117
127
 
@@ -6,16 +6,20 @@ class AutomaticNamespaces::Autoloader
6
6
 
7
7
  def enable_automatic_namespaces
8
8
  namespaced_packages.each do |pack, metadata|
9
- package_namespace = define_namespace(pack, metadata)
10
- pack_directories(pack.path, metadata).each do |pack_dir|
11
- set_namespace_for(pack_dir, package_namespace)
12
- end
9
+ set_namespace_for_pack(pack, metadata)
10
+ end
11
+ end
12
+
13
+ def set_namespace_for_pack(pack, metadata)
14
+ package_namespace = define_namespace(pack, metadata)
15
+ pack_directories(pack.path, metadata).each do |pack_dir|
16
+ set_namespace_for_dir(pack_dir, package_namespace)
13
17
  end
14
18
  end
15
19
 
16
20
  private
17
21
 
18
- def set_namespace_for(pack_dir, package_namespace)
22
+ def set_namespace_for_dir(pack_dir, package_namespace)
19
23
  Rails.logger.debug { "Associating #{pack_dir} with namespace #{package_namespace}" }
20
24
  ActiveSupport::Dependencies.autoload_paths.delete(pack_dir)
21
25
  Rails.autoloaders.main.push_dir(pack_dir, namespace: package_namespace)
@@ -23,7 +27,8 @@ class AutomaticNamespaces::Autoloader
23
27
  end
24
28
 
25
29
  def pack_directories(pack_root_dir, metadata)
26
- Dir.glob("#{pack_root_dir}/**/app/*").select { |dir| namespaced_directory?(dir, metadata) }
30
+ glob = metadata['autoload_glob'] || "/**/app/*"
31
+ Dir.glob("#{pack_root_dir}#{glob}").select { |dir| namespaced_directory?(dir, metadata) }
27
32
  end
28
33
 
29
34
  def namespaced_directory?(dir, metadata)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutomaticNamespaces
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: automatic_namespaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Passero
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-06 00:00:00.000000000 Z
11
+ date: 2025-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description:
97
+ description:
98
98
  email:
99
99
  - gpassero@gmail.com
100
100
  executables: []
@@ -114,7 +114,7 @@ metadata:
114
114
  source_code_uri: https://github.com/gap777/automatic_namespaces
115
115
  changelog_uri: https://github.com/gap777/automatic_namespaces/releases
116
116
  allowed_push_host: https://rubygems.org
117
- post_install_message:
117
+ post_install_message:
118
118
  rdoc_options: []
119
119
  require_paths:
120
120
  - lib
@@ -129,8 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
- rubygems_version: 3.1.6
133
- signing_key:
132
+ rubygems_version: 3.5.11
133
+ signing_key:
134
134
  specification_version: 4
135
135
  summary: Modify autoloading to assume all files within a directory belong in a namespace
136
136
  test_files: []