Class: Yapra::LegacyPlugin::CompatibleModeRegistry
- Inherits:
-
Object
- Object
- Yapra::LegacyPlugin::CompatibleModeRegistry
- Defined in:
- lib/yapra/legacy_plugin/compatible_mode_registry.rb
Instance Attribute Summary collapse
-
#legacy_plugins ⇒ Object
Returns the value of attribute legacy_plugins.
Instance Method Summary collapse
-
#get(module_name) ⇒ Object
load plugin from module name.
-
#initialize(paths, pipeline) ⇒ CompatibleModeRegistry
constructor
- paths
-
Directory paths which contain legacy plugins.
- #logger ⇒ Object
Constructor Details
#initialize(paths, pipeline) ⇒ CompatibleModeRegistry
- paths
-
Directory paths which contain legacy plugins.
- pipeline
-
Runtime pipline.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/yapra/legacy_plugin/compatible_mode_registry.rb', line 10 def initialize paths, pipeline self.legacy_plugins = {} paths.each do |folder| folder = Pathname.new(folder) Pathname.glob(File.join(folder, "**/*.rb")).sort.each do |file| module_name = file.relative_path_from(folder).to_s.gsub("/","::")[0..-4] begin legacy_plugins[ module_name ] = Yapra::LegacyPlugin::Base.new(pipeline, file) logger.debug "#{module_name} is loaded from #{file}" rescue LoadError => ex logger.warn "#{module_name} can't load, because: #{ex.}" end end end end |
Instance Attribute Details
#legacy_plugins ⇒ Object
Returns the value of attribute legacy_plugins.
6 7 8 |
# File 'lib/yapra/legacy_plugin/compatible_mode_registry.rb', line 6 def legacy_plugins @legacy_plugins end |
Instance Method Details
#get(module_name) ⇒ Object
load plugin from module name.
example:
registry = Yapra::LegacyPlugin::CompatibleModeRegistry.new(paths, pipeline)
feed_load_plugin = registry.get('Feed::load')
38 39 40 41 42 |
# File 'lib/yapra/legacy_plugin/compatible_mode_registry.rb', line 38 def get module_name plugin = legacy_plugins[module_name] raise "#{module_name} is not registered." unless plugin plugin end |