Class: Avo::PluginManager
- Inherits:
-
Object
- Object
- Avo::PluginManager
- Defined in:
- lib/avo/plugin_manager.rb
Instance Attribute Summary collapse
-
#plugins ⇒ Object
(also: #all)
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
- #as_json(*arg) ⇒ Object
- #boot_plugins ⇒ Object
- #init_plugins ⇒ Object
-
#initialize ⇒ PluginManager
constructor
A new instance of PluginManager.
- #installed?(name) ⇒ Boolean
- #register(plugin_klass, priority: 10) ⇒ Object
- #register_field(method_name, klass) ⇒ Object
- #register_resource_tool ⇒ Object
- #register_tool ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ PluginManager
Returns a new instance of PluginManager.
7 8 9 |
# File 'lib/avo/plugin_manager.rb', line 7 def initialize @plugins = [] end |
Instance Attribute Details
#plugins ⇒ Object (readonly) Also known as: all
Returns the value of attribute plugins.
3 4 5 |
# File 'lib/avo/plugin_manager.rb', line 3 def plugins @plugins end |
Instance Method Details
#as_json(*arg) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/avo/plugin_manager.rb', line 37 def as_json(*arg) plugins.map do |plugin| { klass: plugin.klass.to_s, priority: plugin.priority, } end end |
#boot_plugins ⇒ Object
15 16 17 18 19 |
# File 'lib/avo/plugin_manager.rb', line 15 def boot_plugins Avo.plugin_manager.all.sort_by(&:priority).each do |plugin| plugin.klass.boot end end |
#init_plugins ⇒ Object
21 22 23 24 25 |
# File 'lib/avo/plugin_manager.rb', line 21 def init_plugins Avo.plugin_manager.all.sort_by(&:priority).each do |plugin| plugin.klass.init end end |
#installed?(name) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/avo/plugin_manager.rb', line 54 def installed?(name) plugins.any? do |plugin| plugin.klass.to_s.chomp("::Plugin").underscore.tr("/", "-") == name.to_s end end |
#register(plugin_klass, priority: 10) ⇒ Object
11 12 13 |
# File 'lib/avo/plugin_manager.rb', line 11 def register(plugin_klass, priority: 10) @plugins << OpenStruct.new(klass: plugin_klass, priority: priority) end |
#register_field(method_name, klass) ⇒ Object
27 28 29 |
# File 'lib/avo/plugin_manager.rb', line 27 def register_field(method_name, klass) Avo.field_manager.load_field method_name, klass end |
#register_resource_tool ⇒ Object
31 32 |
# File 'lib/avo/plugin_manager.rb', line 31 def register_resource_tool end |
#register_tool ⇒ Object
34 35 |
# File 'lib/avo/plugin_manager.rb', line 34 def register_tool end |
#to_s ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/avo/plugin_manager.rb', line 46 def to_s plugins.map do |plugin| plugin.klass.to_s end.join(",") rescue "Failed to fetch plugins." end |