Move constants to isolated file to be loaded on-demand

Since the protos are only loaded when the serve command is invoked, move
the constant alias definitions into an isolated file so they are only
loaded when needed by the serve command
This commit is contained in:
Chris Roberts 2023-05-18 11:49:42 -07:00
parent 5a5eb331cc
commit b0c5852145
2 changed files with 16 additions and 8 deletions

View File

@ -2,17 +2,15 @@ require "optparse"
module VagrantPlugins
module CommandServe
# Simple constant aliases to reduce namespace typing
SDK = Hashicorp::Vagrant::Sdk
SRV = Hashicorp::Vagrant
Empty = ::Google::Protobuf::Empty
autoload :Broker, Vagrant.source_root.join("plugins/commands/serve/broker").to_s
autoload :Client, Vagrant.source_root.join("plugins/commands/serve/client").to_s
autoload :Mappers, Vagrant.source_root.join("plugins/commands/serve/mappers").to_s
autoload :Service, Vagrant.source_root.join("plugins/commands/serve/service").to_s
autoload :Type, Vagrant.source_root.join("plugins/commands/serve/type").to_s
autoload :Util, Vagrant.source_root.join("plugins/commands/serve/util").to_s
autoload :SDK, Vagrant.source_root.join("plugins/commands/serve/constants").to_s
autoload :SRV, Vagrant.source_root.join("plugins/commands/serve/constants").to_s
autoload :Empty, Vagrant.source_root.join("plugins/commands/serve/constants").to_s
class << self
attr_accessor :broker
@ -27,6 +25,11 @@ module VagrantPlugins
require 'grpc'
require 'grpc/health/checker'
require 'grpc/health/v1/health_services_pb'
# Add conversion patches
require Vagrant.source_root.join("plugins/commands/serve/util/direct_conversions.rb").to_s
# Mark dependencies as loaded
@dependencies_loaded = true
end
end
@ -136,6 +139,3 @@ module VagrantPlugins
end
end
end
# Load in our conversions down here so all the autoload stuff is in place
require Vagrant.source_root.join("plugins/commands/serve/util/direct_conversions.rb").to_s

View File

@ -0,0 +1,8 @@
module VagrantPlugins
module CommandServe
# Simple constant aliases to reduce namespace typing
SDK = Hashicorp::Vagrant::Sdk
SRV = Hashicorp::Vagrant
Empty = ::Google::Protobuf::Empty
end
end