Module: Voom::Presenters::Pluggable
- Included in:
- DSL::Components::Base, DSL::UserInterface, WebClient::ComponentRenderer, WebClient::PluginHeaders
- Defined in:
- lib/voom/presenters/pluggable.rb
Instance Method Summary collapse
- #include_plugins(*layers, plugins: [], plugin_method: method(:include)) ⇒ Object
- #plugin(plugin, *layers, plugin_method: method(:include)) ⇒ Object
-
#plugin_module(plugin) ⇒ Object
Returns the module for the specified plugin.
Instance Method Details
#include_plugins(*layers, plugins: [], plugin_method: method(:include)) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/voom/presenters/pluggable.rb', line 6 def include_plugins(*layers, plugins: [], plugin_method: method(:include)) plugins = Array(plugins) + Array(Voom::Presenters::Settings.config.presenters.plugins) plugins.uniq.each do |plugin| plugin(plugin, *layers, plugin_method: plugin_method) end end |
#plugin(plugin, *layers, plugin_method: method(:include)) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/voom/presenters/pluggable.rb', line 26 def plugin(plugin, *layers, plugin_method: method(:include)) m = plugin.is_a?(Module) ? plugin : plugin_module(plugin) layers.each do |layer| if m.const_defined?(layer, false) && !self.const_defined?(layer, false) trace {"Injecting plugin(#{m.const_get(layer).inspect}) into #{self.inspect}!"} plugin_method.call(m.const_get(layer)) end end end |
#plugin_module(plugin) ⇒ Object
Returns the module for the specified plugin. If the module is not defined, the corresponding plugin required.
17 18 19 20 21 22 23 24 |
# File 'lib/voom/presenters/pluggable.rb', line 17 def plugin_module(plugin) module_name = plugin.to_s.gsub(/(^|_)(.)/) {|x| x[-1..-1].upcase} unless Voom::Presenters::Plugins.const_defined?(module_name, false) trace {"Method plugin loading plugin: #{plugin}"} load "voom/presenters/plugins/#{plugin}.rb" end Voom::Presenters::Plugins.const_get(module_name) end |