Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'ernie'
- $:.unshift "#{File.dirname(__FILE__)}/../../../lib"
- require 'breakout/control_center'
- Ernie.class_eval do
- include Singleton
- cattr_accessor :config
- TOOLS_WITH_TEMPLATES = ['trac']
- def logger
- self.class.logger
- end
- def config
- self.class.config
- end
- def initialize
- tools_with_templates = TOOLS_WITH_TEMPLATES.reject { |t| config[t].nil? }
- tools_with_templates.each do |t|
- logger.info "Creating '#{t}' template"
- obj = new_tool t
- obj.send(:prepare_template)
- end
- if config['check_tools']
- config['check_tools'].split.each do |tool|
- obj = new_tool tool
- obj.config = config
- obj.send(:check)
- end
- end
- end
- def new_tool(name)
- name = name.to_s
- raise ArgumentError.new("\"#{name}\" is disabled") if !config[name]
- obj = "Breakout::Control::#{name.capitalize}".constantize.new
- obj.config = config
- obj.logger = logger
- obj.init
- obj
- end
- def self.dispatch(mod, fun, args)
- xargs = BERT::Decoder.convert(args)
- self.log("-- " + [mod, fun, xargs].inspect)
- obj = self.instance.new_tool mod
- res = obj.send(fun, *args)
- BERT::Encoder.convert(res)
- end
- end
- # klass = Breakout::Control::ErnieHandler
- klass = Ernie
- klass.config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../../etc/control.yml"))
- klass.logger = Logger.new("/tmp/ernie.log")
Add Comment
Please, Sign In to add comment