Sha256: 48d298d0bf7d20d3d0433cced2435bf7b04267b9dae5ba2db432e30bb0119318

Contents?: true

Size: 1.53 KB

Versions: 4

Compression:

Stored size: 1.53 KB

Contents

require 'rubygems'

module Chronicle
  module ETL
    # A singleton class that acts as a registry of connector classes available for ETL jobs
    module Registry
      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 install_connector name
          gem_name = "chronicle-#{name}"
          Gem.install(gem_name)
        end

        def register connector
          @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)
          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 }
        end
      end
    end
  end
end

require_relative 'self_registering'
require_relative 'connector_registration'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chronicle-etl-0.4.1 lib/chronicle/etl/registry/registry.rb
chronicle-etl-0.4.0 lib/chronicle/etl/registry/registry.rb
chronicle-etl-0.3.1 lib/chronicle/etl/registry/registry.rb
chronicle-etl-0.3.0 lib/chronicle/etl/registry/registry.rb