module StatsCloud::PluginsHelper
This helper configures StatsCloud
plugins.
Private Instance Methods
build_plugins(plugins)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 11 def build_plugins(plugins) plugins&.each do |plugin| plugin = plugin.is_a?(Hash) ? plugin : simple_plugin_config(plugin) plugin[:class_name] = constantize_plugin_by_name(plugin_class_name_from_plugin(plugin)) end end
constantize_plugin_by_name(plugin_name)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 34 def constantize_plugin_by_name(plugin_name) Object.const_get "StatsCloud::Plugin::#{plugin_name}" rescue NameError raise statscloud_error(no_plugin_error_message(plugin_name)) end
no_plugin_error_message(plugin_name)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 40 def no_plugin_error_message(plugin_name) "Can not find StatsCloud::Plugin::#{plugin_name}. Please require gem to load this plugin" end
plugin_class_name_from_plugin(plugin)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 44 def plugin_class_name_from_plugin(plugin) plugin["name"].split("-").map(&:capitalize).join end
simple_plugin_config(plugin)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 24 def simple_plugin_config(plugin) { "name": plugin } end
start_plugin(plugin, mutex)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 30 def start_plugin(plugin, mutex) plugin[:class_name].start(self, mutex, plugin["settings"]) end
start_plugins_job(plugins, mutex)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 18 def start_plugins_job(plugins, mutex) plugins&.each do |plugin| start_plugin(plugin, mutex) end end
statscloud_error(message)
click to toggle source
# File lib/statscloud/helpers/plugins_helper.rb, line 48 def statscloud_error(message) StatsCloud::ClientError.new(message) end