automatic_namespaces 0.3.1 → 0.4.0
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 +4 -4
- data/README.md +11 -0
- data/lib/automatic_namespaces/autoloader.rb +11 -13
- data/lib/automatic_namespaces/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: eabe8d9d26c2bf99b74b99a047bfb6445eee106a7437571c7062cc163f9f13bf
|
4
|
+
data.tar.gz: 21153b5fe8d5ce982f70964970ad448d75974506435ab67a49f03e881609cb3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e9e6b77583f244650d94c09cf20d41fd8d1b6ec8ed1f95dd9f6345cfef05e588700b03ca8dad75c5b0ebf0cd12328ef1d75f0a975524cb4874face90a3e03c1
|
7
|
+
data.tar.gz: 2e19e2aacb6dd786ac9aacc14cfebd9a0104f5e3fcd5e66dc8916f98c917321911ead978f822ae350ec5dbb054455c6d8a363515f3176198200f36e8d335e686
|
data/README.md
CHANGED
@@ -85,6 +85,17 @@ generally contain namespaced classes. These are exempted from `automatic_namespa
|
|
85
85
|
* javascript
|
86
86
|
* views
|
87
87
|
|
88
|
+
Additional directories can be excluded by adding them to the `automatic_pack_namespace_exclusions` key in your
|
89
|
+
`package.yml` file. This is useful if you require files in your pack that sit outside of your packs namespace:
|
90
|
+
|
91
|
+
```yml
|
92
|
+
metadata:
|
93
|
+
automatic_pack_namespace: true
|
94
|
+
automatic_pack_namespace_exclusions:
|
95
|
+
- app/policies # Exclude pundit policies
|
96
|
+
- app/admin # Exclude active admin definition files
|
97
|
+
```
|
98
|
+
|
88
99
|
If your package / namespace name requires ActiveSupport inflections, you will probably need to tell `automatic_namespaces`
|
89
100
|
what the correct namespace name should be in that package:
|
90
101
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
class AutomaticNamespaces::Autoloader
|
4
|
+
DEFAULT_EXCLUDED_DIRS = %w[/app/helpers /app/inputs /app/javascript /app/views].freeze
|
5
|
+
PACKAGE_EXCLUDED_DIRS_KEY = "automatic_pack_namespace_exclusions".freeze
|
4
6
|
|
5
7
|
def enable_automatic_namespaces
|
6
8
|
namespaced_packages.each do |pack, metadata|
|
7
9
|
package_namespace = define_namespace(pack, metadata)
|
8
|
-
pack_directories(pack.path).each do |pack_dir|
|
10
|
+
pack_directories(pack.path, metadata).each do |pack_dir|
|
9
11
|
set_namespace_for(pack_dir, package_namespace)
|
10
12
|
end
|
11
13
|
end
|
@@ -20,16 +22,16 @@ class AutomaticNamespaces::Autoloader
|
|
20
22
|
Rails.application.config.watchable_dirs[pack_dir] = [:rb]
|
21
23
|
end
|
22
24
|
|
23
|
-
def pack_directories(pack_root_dir)
|
24
|
-
Dir.glob("#{pack_root_dir}/**/app/*").
|
25
|
+
def pack_directories(pack_root_dir, metadata)
|
26
|
+
Dir.glob("#{pack_root_dir}/**/app/*").select { |dir| namespaced_directory?(dir, metadata) }
|
25
27
|
end
|
26
28
|
|
27
|
-
def
|
28
|
-
dir.include?(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
def namespaced_directory?(dir, metadata)
|
30
|
+
excluded_directories(metadata).none? { |excluded_dir| dir.include?(excluded_dir) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def excluded_directories(metadata)
|
34
|
+
DEFAULT_EXCLUDED_DIRS + metadata.fetch(PACKAGE_EXCLUDED_DIRS_KEY, [])
|
33
35
|
end
|
34
36
|
|
35
37
|
def define_namespace(pack, metadata)
|
@@ -59,7 +61,3 @@ class AutomaticNamespaces::Autoloader
|
|
59
61
|
package_description["metadata"]
|
60
62
|
end
|
61
63
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary Passero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|