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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8075b08c9527b8309ac2e784db46c2e9dc6d922b5a4ee7392fbb493ece0bdb8
4
- data.tar.gz: 1f37a85470c68ee132e42e10f26cf3d6be97700d160fbd7479d14bdcd3f23474
3
+ metadata.gz: 92f296666b675bed596644db341453658848f8ff2fff5484a44092627f32e0bf
4
+ data.tar.gz: 369f09117790760fed0f5c9166753626a0ef3e02a75525cdd6346df5779e782c
5
5
  SHA512:
6
- metadata.gz: 158b6e90ec01dc5b1d8f3f9ddad0d91434ba86facfe05b1547aaa4ba3a16679092f6e4c4a83d6c96d3ff1e02724bd1c8d8e4aa42eb45782019f18989036842ba
7
- data.tar.gz: 298cf14dee964a5c6c1029a68a629b3e0cd921ec7f3ff396947919269686c3233a160fe48d36eb7058431f7e8d5be8b9bd174c911c23f4cdf5bed836ea11b8b2
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')
@@ -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) = @registry[name.to_s]
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 = @registry.keys.sort
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 }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.14.0'
5
+ VERSION = '0.14.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-imis-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander