Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. require 'rubygems'
  2. require 'ernie'
  3.  
  4. $:.unshift "#{File.dirname(__FILE__)}/../../../lib"
  5. require 'breakout/control_center'
  6.  
  7. Ernie.class_eval do
  8. include Singleton
  9.  
  10. cattr_accessor :config
  11.  
  12. TOOLS_WITH_TEMPLATES = ['trac']
  13.  
  14. def logger
  15. self.class.logger
  16. end
  17.  
  18. def config
  19. self.class.config
  20. end
  21.  
  22. def initialize
  23. tools_with_templates = TOOLS_WITH_TEMPLATES.reject { |t| config[t].nil? }
  24. tools_with_templates.each do |t|
  25. logger.info "Creating '#{t}' template"
  26. obj = new_tool t
  27. obj.send(:prepare_template)
  28. end
  29.  
  30. if config['check_tools']
  31. config['check_tools'].split.each do |tool|
  32. obj = new_tool tool
  33. obj.config = config
  34. obj.send(:check)
  35. end
  36. end
  37. end
  38.  
  39. def new_tool(name)
  40. name = name.to_s
  41. raise ArgumentError.new("\"#{name}\" is disabled") if !config[name]
  42.  
  43. obj = "Breakout::Control::#{name.capitalize}".constantize.new
  44. obj.config = config
  45. obj.logger = logger
  46. obj.init
  47. obj
  48. end
  49.  
  50. def self.dispatch(mod, fun, args)
  51. xargs = BERT::Decoder.convert(args)
  52. self.log("-- " + [mod, fun, xargs].inspect)
  53.  
  54. obj = self.instance.new_tool mod
  55. res = obj.send(fun, *args)
  56.  
  57. BERT::Encoder.convert(res)
  58. end
  59. end
  60.  
  61. # klass = Breakout::Control::ErnieHandler
  62. klass = Ernie
  63. klass.config = YAML::load(File.open("#{File.dirname(__FILE__)}/../../../etc/control.yml"))
  64. klass.logger = Logger.new("/tmp/ernie.log")
Add Comment
Please, Sign In to add comment