Class: Fusuma::Plugin::Manager
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Manager
- Defined in:
- lib/fusuma/plugin/manager.rb
Overview
Manage Fusuma plugins
Class Method Summary collapse
-
.add(plugin_class:, plugin_path:) ⇒ Object
return [Hash, false].
- .exist?(plugin_class:, plugin_path:) ⇒ Boolean
- .load_paths ⇒ Object
- .plugins ⇒ Object
- .require_plugins_from_config ⇒ Object
- .require_plugins_from_relative ⇒ Object
Instance Method Summary collapse
-
#initialize(plugin_class) ⇒ Manager
constructor
A new instance of Manager.
- #require_siblings_from_gems ⇒ Object
- #require_siblings_from_local ⇒ Object
Constructor Details
#initialize(plugin_class) ⇒ Manager
Returns a new instance of Manager.
10 11 12 |
# File 'lib/fusuma/plugin/manager.rb', line 10 def initialize(plugin_class) @plugin_class = plugin_class end |
Class Method Details
.add(plugin_class:, plugin_path:) ⇒ Object
return [Hash, false]
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fusuma/plugin/manager.rb', line 46 def add(plugin_class:, plugin_path:) return false if exist?(plugin_class: plugin_class, plugin_path: plugin_path) base = plugin_class.superclass.name plugins[base] ||= [] plugins[base] << plugin_class load_paths << plugin_path manager = Manager.new(plugin_class) manager.require_siblings_from_local manager.require_siblings_from_gems end |
.exist?(plugin_class:, plugin_path:) ⇒ Boolean
90 91 92 93 94 95 96 97 |
# File 'lib/fusuma/plugin/manager.rb', line 90 def exist?(plugin_class:, plugin_path:) return false if load_paths.include?(plugin_path) base = plugin_class.superclass.name return false unless plugins[base] plugins[base].include?(plugin_class) end |
.load_paths ⇒ Object
84 85 86 |
# File 'lib/fusuma/plugin/manager.rb', line 84 def load_paths @load_paths ||= [] end |
.plugins ⇒ Object
80 81 82 |
# File 'lib/fusuma/plugin/manager.rb', line 80 def plugins @plugins ||= {} end |
.require_plugins_from_config ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/fusuma/plugin/manager.rb', line 71 def require_plugins_from_config local_plugin_paths = Config.search(Config::Index.new('local_plugin_paths')) return unless local_plugin_paths Array.new(local_plugin_paths).each do |plugin_path| require plugin_path end end |
.require_plugins_from_relative ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fusuma/plugin/manager.rb', line 60 def require_plugins_from_relative require_relative './base.rb' require_relative './events/event.rb' require_relative './inputs/input.rb' require_relative './filters/filter.rb' require_relative './parsers/parser.rb' require_relative './buffers/buffer.rb' require_relative './detectors/detector.rb' require_relative './executors/executor.rb' end |
Instance Method Details
#require_siblings_from_gems ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/fusuma/plugin/manager.rb', line 21 def require_siblings_from_gems search_key = File.join(plugin_dir_name, '*.rb') Gem.find_files(search_key).each do |siblings_plugin| if siblings_plugin =~ %r{fusuma-plugin-(.+).*/lib/#{plugin_dir_name}/\1_.+.rb} require siblings_plugin end end end |
#require_siblings_from_local ⇒ Object
14 15 16 17 18 19 |
# File 'lib/fusuma/plugin/manager.rb', line 14 def require_siblings_from_local search_key = File.join('../../', plugin_dir_name, '*.rb') Dir.glob(File.("#{__dir__}/#{search_key}")).sort.each do |siblings_plugin| require siblings_plugin end end |