lib/chronicle/etl/registry/registry.rb in chronicle-etl-0.4.1 vs lib/chronicle/etl/registry/registry.rb in chronicle-etl-0.4.2
- old
+ new
@@ -18,35 +18,48 @@
require_str = gem.name.gsub('chronicle-', 'chronicle/')
require require_str rescue LoadError
end
end
- def install_connector name
- gem_name = "chronicle-#{name}"
- Gem.install(gem_name)
+ def register connector
+ connectors << connector
end
- def register connector
+ def connectors
@connectors ||= []
- @connectors << connector
end
def find_by_phase_and_identifier(phase, identifier)
- connector = find_within_loaded_connectors(phase, identifier)
- unless connector
- # Only load external connectors (slow) if not found in built-in connectors
- load_all!
- connector = find_within_loaded_connectors(phase, identifier)
+ # Simple case: built in connector
+ connector = connectors.find { |c| c.phase == phase && c.identifier == identifier }
+ return connector if connector
+
+ # if not available in built-in connectors, try to activate a
+ # relevant plugin and try again
+ if identifier.include?(":")
+ plugin, name = identifier.split(":")
+ else
+ # This case handles the case where the identifier is a
+ # shorthand (ie `imessage`) because there's only one default
+ # connector.
+ plugin = identifier
end
- connector || raise(ConnectorNotAvailableError.new("Connector '#{identifier}' not found"))
- end
- def find_within_loaded_connectors(phase, identifier)
- @connectors.find { |c| c.phase == phase && c.identifier == identifier }
+ PluginRegistry.activate(plugin)
+
+ candidates = connectors.select { |c| c.phase == phase && c.plugin == plugin }
+ # if no name given, just use first connector with right phase/plugin
+ # TODO: set up a property for connectors to specify that they're the
+ # default connector for the plugin
+ candidates = candidates.select { |c| c.identifier == name } if name
+ connector = candidates.first
+
+ connector || raise(ConnectorNotAvailableError, "Connector '#{identifier}' not found")
end
end
end
end
end
require_relative 'self_registering'
require_relative 'connector_registration'
+require_relative 'plugin_registry'