Skip to content

Commit

Permalink
Change the mechanism for load plug-in
Browse files Browse the repository at this point in the history
  • Loading branch information
daichirata committed Feb 22, 2012
1 parent 5d466a4 commit 7fc1afb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions lib/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,25 @@
# License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0.

class Automatic
require 'pathname'
require 'yaml'

def self.core(recipe)
basedir = File.dirname(__FILE__)
$:.unshift File.join(basedir, '..', 'plugins', 'subscription')
$:.unshift File.join(basedir, '..', 'plugins', 'filter')
$:.unshift File.join(basedir, '..', 'plugins', 'store')
$:.unshift File.join(basedir, '..', 'plugins', 'publish')
basedir = Pathname.new(__FILE__).parent.parent
recipe = basedir + 'config/default.yml' if recipe.empty?

Dir.glob(basedir + '/../plugins/**/*.rb').each {|r|
require(File.basename(r, '.rb'))
}
Pathname.glob(basedir + 'plugins/*/*.rb').each do |path|
klass_name =
path.parent.basename.to_s.split('_').map(&:capitalize).join +
path.basename('.rb').to_s.split('_').map(&:capitalize).join

require 'yaml'
if recipe == ""
recipe = basedir + '/../config/default.yml'
autoload klass_name.to_sym, path
end

File.open(recipe) {|io|
YAML.load_documents(io) {|yaml|
@pipeline = []
yaml['plugins'].each {|plugin|
loader = eval(plugin['module']).new(plugin['config'], @pipeline)
@pipeline = loader.run
}
}
}
@pipeline = []
YAML.load(File.read(recipe))['plugins'].each do |plugin|
klass = eval(plugin['module'])
@pipeline = klass.new(plugin['config'], @pipeline).run
end
end
end
File renamed without changes.

0 comments on commit 7fc1afb

Please sign in to comment.