usps-imis-api 0.14.0 → 0.14.1
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/usps/imis/command_line/interface.rb +5 -0
- data/lib/usps/imis/models.rb +51 -16
- data/lib/usps/imis/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92f296666b675bed596644db341453658848f8ff2fff5484a44092627f32e0bf
|
|
4
|
+
data.tar.gz: 369f09117790760fed0f5c9166753626a0ef3e02a75525cdd6346df5779e782c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89af34efab0e554f3a4c0091ffca5bdf6b972fdd13b8e1b62e73e894a0fe83adba858a4a4bf2b25756f4d4c5e7fa909ef8601b53f0976163c1179a1873ed22b6
|
|
7
|
+
data.tar.gz: 56c89598f8a3b53fbbc697b96855c45af807318a80f180727e7354e3c4de246903ebd03a87da9c6ca2624fdbcd7d244901c03a739000cd37f7d062b41d6cfc0a
|
|
@@ -45,6 +45,11 @@ module Usps
|
|
|
45
45
|
@options = input_options.merge(**)
|
|
46
46
|
options[:version] = true if default_options?
|
|
47
47
|
|
|
48
|
+
# Skip model loading, unless we explicitly need it, because the CLI
|
|
49
|
+
# generally only works with raw response data
|
|
50
|
+
#
|
|
51
|
+
Usps::Imis::Models.skip! unless options[:business_objects]
|
|
52
|
+
|
|
48
53
|
configure!
|
|
49
54
|
logging!
|
|
50
55
|
@logger = Imis.logger('CommandLine')
|
data/lib/usps/imis/models.rb
CHANGED
|
@@ -21,11 +21,17 @@ module Usps
|
|
|
21
21
|
# Look up the registered Model class for an iMIS Business Object name.
|
|
22
22
|
# Returns +nil+ if none is registered.
|
|
23
23
|
#
|
|
24
|
-
def for_entity(name)
|
|
24
|
+
def for_entity(name)
|
|
25
|
+
load!
|
|
26
|
+
@registry[name.to_s]
|
|
27
|
+
end
|
|
25
28
|
|
|
26
29
|
# All registered Business Object names, sorted.
|
|
27
30
|
#
|
|
28
|
-
def entity_names
|
|
31
|
+
def entity_names
|
|
32
|
+
load!
|
|
33
|
+
@registry.keys.sort
|
|
34
|
+
end
|
|
29
35
|
|
|
30
36
|
# Register a Model subclass under its +business_object_name+. Called
|
|
31
37
|
# from +Base.business_object+; tests can call +deregister+ for cleanup.
|
|
@@ -35,23 +41,52 @@ module Usps
|
|
|
35
41
|
# Remove a Model subclass from the routing registry.
|
|
36
42
|
#
|
|
37
43
|
def deregister(name) = @registry.delete(name.to_s)
|
|
44
|
+
|
|
45
|
+
# Require all model files. Hand-written files at the top level go first
|
|
46
|
+
# (some — e.g. party.rb — require their own subdirectory). Auto-generated
|
|
47
|
+
# wrappers under generated/ are loaded next. Finally, files in associations/
|
|
48
|
+
# reopen previously-loaded classes to declare cross-model relationships;
|
|
49
|
+
# they're separated from generated/ so the generator doesn't clobber them.
|
|
50
|
+
#
|
|
51
|
+
# Deferred until first registry lookup so CLI startup (--help, --version)
|
|
52
|
+
# doesn't pay the cost of requiring several hundred model files.
|
|
53
|
+
#
|
|
54
|
+
# Trigger lazy load when callers reference a model constant directly
|
|
55
|
+
# (e.g. +Usps::Imis::Models::Party+) before any registry lookup has
|
|
56
|
+
# forced loading.
|
|
57
|
+
#
|
|
58
|
+
def const_missing(name)
|
|
59
|
+
return super if loaded? || skipped? || name == :Base
|
|
60
|
+
|
|
61
|
+
load!
|
|
62
|
+
const_get(name)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def load!
|
|
66
|
+
return if loaded? || skipped?
|
|
67
|
+
|
|
68
|
+
dir = File.expand_path('models', __dir__)
|
|
69
|
+
paths =
|
|
70
|
+
Dir[File.join(dir, '*.rb')] +
|
|
71
|
+
Dir[File.join(dir, 'generated', '*.rb')] +
|
|
72
|
+
Dir[File.join(dir, 'associations', '*.rb')]
|
|
73
|
+
paths
|
|
74
|
+
.reject { it.end_with?('models/base.rb') }
|
|
75
|
+
.map { it.sub(/\.rb$/, '') }
|
|
76
|
+
.each { require it }
|
|
77
|
+
|
|
78
|
+
@loaded = true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def skip!
|
|
82
|
+
@skipped = true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def loaded? = @loaded
|
|
86
|
+
def skipped? = @skipped
|
|
38
87
|
end
|
|
39
88
|
end
|
|
40
89
|
end
|
|
41
90
|
end
|
|
42
91
|
|
|
43
92
|
require_relative 'models/base'
|
|
44
|
-
|
|
45
|
-
# Require all other model files. Hand-written files at the top level go first
|
|
46
|
-
# (some — e.g. party.rb — require their own subdirectory). Auto-generated
|
|
47
|
-
# wrappers under generated/ are loaded next. Finally, files in associations/
|
|
48
|
-
# reopen previously-loaded classes to declare cross-model relationships;
|
|
49
|
-
# they're separated from generated/ so the generator doesn't clobber them.
|
|
50
|
-
paths =
|
|
51
|
-
Dir[File.join(__dir__, 'models', '*.rb')] +
|
|
52
|
-
Dir[File.join(__dir__, 'models', 'generated', '*.rb')] +
|
|
53
|
-
Dir[File.join(__dir__, 'models', 'associations', '*.rb')]
|
|
54
|
-
paths
|
|
55
|
-
.reject { it.end_with?('models/base.rb') }
|
|
56
|
-
.map { it.sub(/\.rb$/, '') }
|
|
57
|
-
.each { require it }
|
data/lib/usps/imis/version.rb
CHANGED