Permalink
Browse files

Simplify plugin init

Utilize the PluginManager to initialize routines instead of duplicating
code. Also globalized $LOG_LEVEL since it's required by PluginManager.
  • Loading branch information...
1 parent 4452d33 commit ab94c4046bd9c2e0eb5cecae23fce33480c31297 Kyle committed Feb 24, 2013
Showing with 9 additions and 18 deletions.
  1. +9 −18 lib/siriproxy/command_line.rb
@@ -9,6 +9,8 @@ class SiriProxy
end
class SiriProxy::CommandLine
+ $LOG_LEVEL = 0
+
BANNER = <<-EOS
Siri Proxy is a proxy server for Apple's Siri "assistant." The idea is to allow for the creation of custom handlers for different actions. This can allow developers to easily add functionality to Siri.
@@ -46,7 +48,8 @@ def initialize
def run_console
load_code
- $LOG_LEVEL = 0
+ init_plugins
+
# this is ugly, but works for now
SiriProxy::PluginManager.class_eval do
def respond(text, options={})
@@ -191,24 +194,12 @@ def load_code
end
def init_plugins
- if $APP_CONFIG.plugins
- $APP_CONFIG.plugins.each_with_index do |pluginConfig, i|
- if pluginConfig.is_a? String
- className = pluginConfig
- requireName = "siriproxy-#{className.downcase}"
- else
- className = pluginConfig['name']
- requireName = pluginConfig['require'] || "siriproxy-#{className.downcase}"
- end
- require requireName
- plugin = SiriProxy::Plugin.const_get(className).new(pluginConfig)
-
- if plugin.respond_to?('plugin_init')
- $APP_CONFIG.plugins[i]['init'] = plugin.plugin_init
- end
-
- plugin = nil
+ pManager = SiriProxy::PluginManager.new
+ pManager.plugins.each_with_index do |plugin, i|
+ if plugin.respond_to?('plugin_init')
+ $APP_CONFIG.plugins[i]['init'] = plugin.plugin_init
end
end
+ pManager = nil
end
end

0 comments on commit ab94c40

Please sign in to comment.