lib/chronicle/etl/registry/registry.rb in chronicle-etl-0.4.4 vs lib/chronicle/etl/registry/registry.rb in chronicle-etl-0.5.0

- old
+ new

@@ -7,32 +7,26 @@ PHASES = [:extractor, :transformer, :loader] class << self attr_accessor :connectors - def load_all! - load_connectors_from_gems - end - - def load_connectors_from_gems - Gem::Specification.filter{|s| s.name.match(/^chronicle/) }.each do |gem| - require_str = gem.name.gsub('chronicle-', 'chronicle/') - require require_str rescue LoadError - end - end - - def register connector + def register(connector) connectors << connector end def connectors @connectors ||= [] end - def find_by_phase_and_identifier(phase, identifier) - # Simple case: built in connector + # Find connector from amongst those currently loaded + def find_by_phase_and_identifier_local(phase, identifier) connector = connectors.find { |c| c.phase == phase && c.identifier == identifier } + end + + # Find connector and load relevant plugin to find it if necessary + def find_by_phase_and_identifier(phase, identifier) + connector = find_by_phase_and_identifier_local(phase, identifier) return connector if connector # if not available in built-in connectors, try to activate a # relevant plugin and try again if identifier.include?(":") @@ -41,9 +35,11 @@ # This case handles the case where the identifier is a # shorthand (ie `imessage`) because there's only one default # connector. plugin = identifier end + + raise(Chronicle::ETL::PluginNotInstalledError.new(plugin)) unless PluginRegistry.installed?(plugin) 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