automatic_namespaces 0.3.0 → 0.4.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: b98197aef26bbea5b268b32ade2377e646d65eb5ced3e1d89c0c15930d0cede3
4
- data.tar.gz: 0bf0c76a057ebf5a9e9dec1e7e4ef6583efdef60f84325aaa4cc8a683d073a18
3
+ metadata.gz: eabe8d9d26c2bf99b74b99a047bfb6445eee106a7437571c7062cc163f9f13bf
4
+ data.tar.gz: 21153b5fe8d5ce982f70964970ad448d75974506435ab67a49f03e881609cb3a
5
5
  SHA512:
6
- metadata.gz: 59f1594f6822e1f3d6eac4f2571423edd2ff079a13ec0748b39f63e55d720b8bf63a4139151778e6863a1e82e1848740b72687dd2a127b2cdab898b0b766a3fd
7
- data.tar.gz: b38559506c30a6e40f72751692a2540bde040faea2dbee8c5c063d7dadbda14c5db963e35d4b99b3936eba93f4446ac95a58c3e3a79e69c4389099bf6ad7d3ac
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.0"
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.0
4
+ version: 0.4.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-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
@@ -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.2.15
133
- signing_key:
132
+ rubygems_version: 3.1.6
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: []