class Embulk::PluginRegistry

Attributes

category[R]

Public Class Methods

new(category, search_prefix) click to toggle source
# File lib/embulk/plugin_registry.rb, line 7
def initialize(category, search_prefix)
  @category = category
  @search_prefix = search_prefix
  @loaded_gems = {}
  @map = {}
end

Public Instance Methods

lookup(type) click to toggle source
# File lib/embulk/plugin_registry.rb, line 21
def lookup(type)
  type = type.to_sym
  if value = @map[type]
    return value
  end
  if search(type)
    if value = @map[type]
      return value
    end
    raise PluginLoadError.new "Unknown #{@category} plugin '#{type}'. #{@search_prefix}#{type}.rb is installed but it does not correctly register plugin."
  else
    raise PluginLoadError.new "Unknown #{@category} plugin '#{type}'. #{@search_prefix}#{type}.rb is not installed. Run 'embulk gem search -rd embulk-#{@category}' command to find plugins."
  end
end
register(type, value) click to toggle source
# File lib/embulk/plugin_registry.rb, line 16
def register(type, value)
  type = type.to_sym
  @map[type] = value
end
require_and_show(path, spec=nil) click to toggle source
# File lib/embulk/plugin_registry.rb, line 80
def require_and_show(path, spec=nil)
  require path
  unless spec
    name, spec = Kernel::RUBYGEMS_ACTIVATION_MONITOR.synchronize do  # this lock is added as a workaround of https://github.com/jruby/jruby/issues/3652
      Gem.loaded_specs.find {|name,spec|
        #spec.files.include?(path)
        spec.contains_requirable_file?(path)
      }
    end
  end
  if spec
    unless @loaded_gems[spec.name]
      Embulk.logger.info "Loaded plugin #{spec.name} (#{spec.version})"
      @loaded_gems[spec.name]
    end
  else
    Embulk.logger.info "Loaded plugin #{path} from a load path"
  end
end