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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4591f54c57c3df9887c0321b7105e03873f7f922576b9cbc6385dae4c40a1c11
4
- data.tar.gz: 3f478d56630b968d7b22d4f3feac07eadd9ed22535667a34d824fa8e3067f929
3
+ metadata.gz: eabe8d9d26c2bf99b74b99a047bfb6445eee106a7437571c7062cc163f9f13bf
4
+ data.tar.gz: 21153b5fe8d5ce982f70964970ad448d75974506435ab67a49f03e881609cb3a
5
5
  SHA512:
6
- metadata.gz: 2c8c2b1df45d0a7e6273a7f2b01ad521d87bd5ede3ca5f2e47107981191f4949c9fb997fe93478f97daf256b3499271ddd9ab865940940d82196795a01e7a9ee
7
- data.tar.gz: 7f6c638a11fc1c3ec1b70591f3f18e8d60f49c18f07e051281bd8c002da15b645ef9e34b9869b8eecebb398a72b4987652b48d01252541d974f8bde358c3a5bc
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/*").reject { |dir| non_namspaced_directory(dir) }
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 non_namspaced_directory(dir)
28
- dir.include?('/app/assets') ||
29
- dir.include?('/app/helpers') || # Rails assumes helpers are global, not namespaced
30
- dir.include?('/app/inputs') || # Not sure how to namespace form inputs
31
- dir.include?('/app/javascript') ||
32
- dir.include?('/app/views')
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
-
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AutomaticNamespaces
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.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.3.1
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-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport