automatic_namespaces 0.5.0 → 0.5.3
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/lib/automatic_namespaces/autoloader.rb +17 -5
- data/lib/automatic_namespaces/version.rb +1 -1
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 376744f1eec7a16bf39c8ddde12cb59d02aed6cf895544b77f562b43a102c873
|
|
4
|
+
data.tar.gz: 19b70861709bd30b9f3b530ba51c00d5608df1502c9b8bc934f386c7cb352aeb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32c49acbf1ed5631dae92e124c1302529741112681252a053c18ef5ba46e08ccf6e266a83efae708b48b12f869133f09fae07cc6e4ff6be8ed4a5d85e545c6c6
|
|
7
|
+
data.tar.gz: 1d5a1121f91a15ce37fdee94111e59a92ebf740969a52e91c9d0e18de037a47b705fdea7397591453f8104928a2a83436b3d0bfc604ff5c0d606d12901b97f69
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
2
|
|
|
3
3
|
class AutomaticNamespaces::Autoloader
|
|
4
|
-
|
|
4
|
+
ROOT_KEY = "automatic_pack_namespace".freeze
|
|
5
5
|
PACKAGE_EXCLUDED_DIRS_KEY = "automatic_pack_namespace_exclusions".freeze
|
|
6
|
+
PACKAGE_AUTOLOAD_GLOB_KEY_OLD = "autoload_glob".freeze
|
|
7
|
+
PACKAGE_AUTOLOAD_GLOB_KEY = "automatic_pack_namespace_autoload_glob".freeze
|
|
8
|
+
PACKAGE_NAMESPACE_OVERRIDE_KEY_OLD = "namespace_override".freeze
|
|
9
|
+
|
|
10
|
+
DEFAULT_EXCLUDED_DIRS = %w[/app/helpers /app/inputs /app/javascript /app/views].freeze
|
|
6
11
|
|
|
7
12
|
def enable_automatic_namespaces
|
|
8
13
|
namespaced_packages.each do |pack, metadata|
|
|
@@ -27,7 +32,7 @@ class AutomaticNamespaces::Autoloader
|
|
|
27
32
|
end
|
|
28
33
|
|
|
29
34
|
def pack_directories(pack_root_dir, metadata)
|
|
30
|
-
glob = metadata[
|
|
35
|
+
glob = metadata[PACKAGE_AUTOLOAD_GLOB_KEY] || metadata[PACKAGE_AUTOLOAD_GLOB_KEY_OLD] || "/**/app/*"
|
|
31
36
|
Dir.glob("#{pack_root_dir}#{glob}").select { |dir| namespaced_directory?(dir, metadata) }
|
|
32
37
|
end
|
|
33
38
|
|
|
@@ -40,14 +45,21 @@ class AutomaticNamespaces::Autoloader
|
|
|
40
45
|
end
|
|
41
46
|
|
|
42
47
|
def define_namespace(pack, metadata)
|
|
43
|
-
namespace_name = metadata['namespace_override'] || pack.last_name.camelize
|
|
44
48
|
namespace_object = Object
|
|
45
|
-
namespace_name.split('::').each do |module_name|
|
|
49
|
+
namespace_name(pack, metadata).split('::').each do |module_name|
|
|
46
50
|
namespace_object = find_or_create_module(namespace_object, module_name)
|
|
47
51
|
end
|
|
48
52
|
namespace_object
|
|
49
53
|
end
|
|
50
54
|
|
|
55
|
+
def namespace_name(pack, metadata)
|
|
56
|
+
if [true, false, "true", "false"].exclude?(metadata[ROOT_KEY])
|
|
57
|
+
metadata[ROOT_KEY]
|
|
58
|
+
else
|
|
59
|
+
metadata[PACKAGE_NAMESPACE_OVERRIDE_KEY_OLD] || pack.last_name.camelize
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
51
63
|
def find_or_create_module(namespace_object, module_name)
|
|
52
64
|
namespace_object.const_defined?(module_name) ?
|
|
53
65
|
namespace_object.const_get(module_name) :
|
|
@@ -57,7 +69,7 @@ class AutomaticNamespaces::Autoloader
|
|
|
57
69
|
def namespaced_packages
|
|
58
70
|
Packs.all
|
|
59
71
|
.map {|pack| [pack, package_metadata(pack)] }
|
|
60
|
-
.select {|_pack, metadata| metadata && metadata[
|
|
72
|
+
.select {|_pack, metadata| metadata && metadata[ROOT_KEY] }
|
|
61
73
|
end
|
|
62
74
|
|
|
63
75
|
def package_metadata(pack)
|
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.5.
|
|
4
|
+
version: 0.5.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gary Passero
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 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.
|
|
133
|
-
signing_key:
|
|
129
|
+
rubygems_version: 3.6.9
|
|
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: []
|