projects/command_connectors/src/command_connector.rb in foobara-0.0.11 vs projects/command_connectors/src/command_connector.rb in foobara-0.0.12

- old
+ new

@@ -248,10 +248,28 @@ Util.array(default_serializers).each do |serializer| add_default_serializer(serializer) end end + def connect_delayed(registerable_name, *args, **opts) + delayed_connections[registerable_name] = { args:, opts: } + end + + def delayed_connections + @delayed_connections ||= {} + end + + def process_delayed_connections + delayed_connections.each_pair do |registerable_name, arg_hash| + args = arg_hash[:args] + opts = arg_hash[:opts] || {} + + const = Object.const_get(registerable_name) + connect(const, *args, **opts) + end + end + def connect(registerable, *, **) case registerable when Class unless registerable < Command # :nocov: @@ -272,10 +290,12 @@ else # :nocov: raise "Don't know how to register #{registerable} (#{registerable.class})" # :nocov: end + when Symbol, String + connect_delayed(registerable, *, **) else # :nocov: raise "Don't know how to register #{registerable} (#{registerable.class})" # :nocov: end @@ -285,10 +305,12 @@ self.class::Request.new(...) end # TODO: maybe introduce a Runner interface? def run(*, **) + process_delayed_connections + request, command = build_request_and_command(*, **) # TODO: feels like a smell request.command_connector = self @@ -323,10 +345,12 @@ def type_from_name(name) Foobara.foobara_lookup_type(name, mode: Namespace::LookupMode::RELAXED) end def foobara_manifest + process_delayed_connections + # Drive all of this off of the list of exposed commands... to_include = Set.new to_include << command_registry.exposed_global_organization to_include << command_registry.exposed_global_domain @@ -408,9 +432,11 @@ [key, entries.sort.to_h] end.sort.to_h end def all_exposed_commands + process_delayed_connections + command_registry.foobara_all_command end end end