Yapra::Pipeline

Constants

UPPER_CASE

Attributes

legacy_plugin_registry[RW]

Public Instance Methods

execute_plugin(command, data) click to toggle source
# File lib/yapra/pipeline.rb, line 51
def execute_plugin command, data
  self.logger.info("exec plugin #{command["module"]}")
  if class_based_plugin?(command['module'])
    run_class_based_plugin command, data
  else
    run_legacy_plugin command, data
  end
end
run(pipeline_command, data=[]) click to toggle source

start pipeline from commands.

example:

pipeline.run([
  {
    'module' => 'Config::agent',
    'config' => {
      'user_agent_alias' => 'Windows IE 6'
    }
  },
  {
    'module' => 'RSS::load',
    'config' => {
      'uri' => 'http://www.example.com/hoge.rdf'
    }
  },
  {
    'module' => 'print'
  }
])
# File lib/yapra/pipeline.rb, line 33
def run pipeline_command, data=[]
  @plugins = []
  begin
    pipeline_command.inject(data) do |data, command|
      execute_plugin(command, data.clone)
    end
  rescue => ex
    @plugins.each do |plugin|
      begin
        plugin.on_error(ex) if plugin.respond_to?('on_error')
      rescue => exx
        self.logger.error("error is occured when error handling: #{exx.message}")
      end
    end
    raise ex
  end
end

Protected Instance Methods

class_based_plugin?(command_name) click to toggle source
# File lib/yapra/pipeline.rb, line 61
def class_based_plugin? command_name
  UPPER_CASE =~ command_name.split('::').last[0, 1]
end
raise_load_error(load_error_stack, command) click to toggle source
# File lib/yapra/pipeline.rb, line 83
def raise_load_error load_error_stack, command
  load_error = LoadError.new("#{command['module']} module is not found.")
  backtrace = load_error.backtrace || []
  load_error_stack.each do |e|
    backtrace << "#{e.class.name} in '#{e.message}'"
    backtrace = backtrace + e.backtrace
  end
  load_error.set_backtrace(backtrace)
  raise load_error
end
run_class_based_plugin(command, data) click to toggle source
# File lib/yapra/pipeline.rb, line 71
def run_class_based_plugin command, data
  self.logger.debug("evaluate plugin as class based")
  plugin = load(command)
  
  # yml pipeline specific.
  plugin.plugin_config  = command['config'] if plugin.respond_to?('plugin_config=')
  
  @plugins << plugin
  data = plugin.run(data)
  return data
end
run_legacy_plugin(command, data) click to toggle source
# File lib/yapra/pipeline.rb, line 65
def run_legacy_plugin command, data
  self.logger.debug("evaluate plugin as legacy")
  data = legacy_plugin_registry.get(command['module'])._yapra_run_as_legacy_plugin(command['config'], data)
  return data
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.