automatic_namespaces 0.4.0 → 0.5.2

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: 748dacb562a8622a1288a39b7036364a09cb0a8a5e19b2862a3e1145bd7f5549
4
+ data.tar.gz: abe1ffc72d71e4bd1f49bab3ea60066a43e3ab8e61ee7304f9fbe400bedc206f
5
5
  SHA512:
6
- metadata.gz: 6e9e6b77583f244650d94c09cf20d41fd8d1b6ec8ed1f95dd9f6345cfef05e588700b03ca8dad75c5b0ebf0cd12328ef1d75f0a975524cb4874face90a3e03c1
7
- data.tar.gz: 2e19e2aacb6dd786ac9aacc14cfebd9a0104f5e3fcd5e66dc8916f98c917321911ead978f822ae350ec5dbb054455c6d8a363515f3176198200f36e8d335e686
6
+ metadata.gz: 2b2b6df942abf3c07bb88d3c2338e6614bc799d926adfac6271c70df6484ae58ae2d0cdd5cbfc861c7a364442bd84fefb9b93462b677923b506641426f4cb750
7
+ data.tar.gz: a68100758eda2db63a1c917e567c2a5d33591f47c9b09b14848d00bd4abc22f37ecaf70575e8c562d491dcd7de0fb439f2fa025e39323267160a1b7d07fc513b
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.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Passero
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-03-06 00:00:00.000000000 Z
10
+ date: 2025-01-15 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -94,7 +93,6 @@ dependencies:
94
93
  - - ">="
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
- description:
98
96
  email:
99
97
  - gpassero@gmail.com
100
98
  executables: []
@@ -114,7 +112,6 @@ metadata:
114
112
  source_code_uri: https://github.com/gap777/automatic_namespaces
115
113
  changelog_uri: https://github.com/gap777/automatic_namespaces/releases
116
114
  allowed_push_host: https://rubygems.org
117
- post_install_message:
118
115
  rdoc_options: []
119
116
  require_paths:
120
117
  - lib
@@ -129,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
126
  - !ruby/object:Gem::Version
130
127
  version: '0'
131
128
  requirements: []
132
- rubygems_version: 3.1.6
133
- signing_key:
129
+ rubygems_version: 3.6.2
134
130
  specification_version: 4
135
131
  summary: Modify autoloading to assume all files within a directory belong in a namespace
136
132
  test_files: []