class Embulk::PluginManager

Public Class Methods

new() click to toggle source
# File lib/embulk/plugin.rb, line 21
def initialize
  @registries = {}
  %w[input output parser formatter decoder encoder line_filter filter guess executor].each do |category|
    @registries[category.to_sym] = PluginRegistry.new(category, "embulk/#{category}/")
  end
end

Public Instance Methods

get_guess(type) click to toggle source
TODO EncoderPlugin::RubyAdapter is not written by anyone yet

def get_encoder(type)

# TODO not implemented yet
lookup(:encoder, type)

end

# File lib/embulk/plugin.rb, line 103
def get_guess(type)
  lookup(:guess, type)
end
new_java_decoder(type) click to toggle source
# File lib/embulk/plugin.rb, line 174
def new_java_decoder(type)
  lookup(:decoder, type).new_java
end
new_java_encoder(type) click to toggle source
# File lib/embulk/plugin.rb, line 178
def new_java_encoder(type)
  lookup(:encoder, type).new_java
end
new_java_executor(type) click to toggle source
# File lib/embulk/plugin.rb, line 186
def new_java_executor(type)
  lookup(:executor, type).new_java
end
new_java_filter(type) click to toggle source
# File lib/embulk/plugin.rb, line 162
def new_java_filter(type)
  lookup(:filter, type).new_java
end
new_java_formatter(type) click to toggle source
# File lib/embulk/plugin.rb, line 170
def new_java_formatter(type)
  lookup(:formatter, type).new_java
end
new_java_guess(type) click to toggle source
# File lib/embulk/plugin.rb, line 182
def new_java_guess(type)
  lookup(:guess, type).new_java
end
new_java_input(type) click to toggle source
# File lib/embulk/plugin.rb, line 154
def new_java_input(type)
  lookup(:input, type).new_java
end
new_java_output(type) click to toggle source
# File lib/embulk/plugin.rb, line 158
def new_java_output(type)
  lookup(:output, type).new_java
end
new_java_parser(type) click to toggle source
# File lib/embulk/plugin.rb, line 166
def new_java_parser(type)
  lookup(:parser, type).new_java
end
register_filter(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 37
def register_filter(type, klass)
  register_plugin(:filter, type, klass, FilterPlugin)
end
register_formatter(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 45
def register_formatter(type, klass)
  register_plugin(:formatter, type, klass, FormatterPlugin)
end
register_guess(type, klass) click to toggle source
TODO EncoderPlugin JRuby API is not written by anyone yet

def register_encoder(type, klass)

register_plugin(:encoder, type, klass, EncoderPlugin)

end

# File lib/embulk/plugin.rb, line 59
def register_guess(type, klass)
  register_plugin(:guess, type, klass, GuessPlugin,
                 "Guess plugin #{klass} must extend GuessPlugin, LineGuessPlugin, or TextGuessPlugin class")
end
register_input(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 28
def register_input(type, klass)
  register_plugin(:input, type, klass, InputPlugin)
end
register_java_decoder(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 134
def register_java_decoder(type, klass)
  register_java_plugin(:decoder, type, klass,
                       "org.embulk.spi.DecoderPlugin" => DecoderPlugin)
end
register_java_encoder(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 139
def register_java_encoder(type, klass)
  register_java_plugin(:encoder, type, klass,
                       "org.embulk.spi.EncoderPlugin" => EncoderPlugin)
end
register_java_executor(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 149
def register_java_executor(type, klass)
  register_java_plugin(:executor, type, klass,
                       "org.embulk.spi.ExecutorPlugin" => ExecutorPlugin)
end
register_java_filter(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 119
def register_java_filter(type, klass)
  register_java_plugin(:filter, type, klass,
                       "org.embulk.spi.FilterPlugin" => FilterPlugin)
end
register_java_formatter(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 129
def register_java_formatter(type, klass)
  register_java_plugin(:formatter, type, klass,
                       "org.embulk.spi.FormatterPlugin" => FormatterPlugin)
end
register_java_guess(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 144
def register_java_guess(type, klass)
  register_java_plugin(:guess, type, klass,
                       "org.embulk.spi.GuessPlugin" => GuessPlugin)
end
register_java_input(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 107
def register_java_input(type, klass)
  register_java_plugin(:input, type, klass,
                       "org.embulk.spi.InputPlugin" => InputPlugin,
                       "org.embulk.spi.FileInputPlugin" => FileInputPlugin)
end
register_java_output(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 113
def register_java_output(type, klass)
  register_java_plugin(:output, type, klass,
                       "org.embulk.spi.OutputPlugin" => OutputPlugin,
                       "org.embulk.spi.FileOutputPlugin" => FileOutputPlugin)
end
register_java_parser(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 124
def register_java_parser(type, klass)
  register_java_plugin(:parser, type, klass,
                       "org.embulk.spi.ParserPlugin" => ParserPlugin)
end
register_output(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 32
def register_output(type, klass)
  register_plugin(:output, type, klass, OutputPlugin,
                  "Output plugin #{klass} must extend OutputPlugin")
end
register_parser(type, klass) click to toggle source
# File lib/embulk/plugin.rb, line 41
def register_parser(type, klass)
  register_plugin(:parser, type, klass, ParserPlugin)
end

Private Instance Methods

lookup(category, type) click to toggle source

TODO lookup should fallback to Java PluginSource if not found so that ruby plugins can call java plugins. call Java.injector.newPlugin and wrap the instance in a reverse bridge object.

# File lib/embulk/plugin.rb, line 196
def lookup(category, type)
  @registries[category].lookup(type)
end
register_java_plugin(category, type, klass, iface_map, message=nil) click to toggle source
# File lib/embulk/plugin.rb, line 208
def register_java_plugin(category, type, klass, iface_map, message=nil)
  found = iface_map.find do |iface_name,ruby_base_class|
    iface = JRuby.runtime.getJRubyClassLoader.load_class(iface_name)
    iface.isAssignableFrom(klass)
  end
  unless found
    message ||= "Java plugin #{klass} must implement #{iface_map.keys.join(' or ')}"
    raise message
  end
  adapted = found.last.from_java(klass)
  @registries[category].register(type, adapted)
end
register_plugin(category, type, klass, base_class, message=nil) click to toggle source
# File lib/embulk/plugin.rb, line 200
def register_plugin(category, type, klass, base_class, message=nil)
  unless klass < base_class
    message ||= "Plugin #{klass} must inherit #{base_class}"
    raise message
  end
  @registries[category].register(type, klass)
end