Class: Yapra::LegacyPlugin::CompatibleModeRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/yapra/legacy_plugin/compatible_mode_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message}"
      end
    end
  end
end

Instance Attribute Details

#legacy_pluginsObject

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

#loggerObject



27
28
29
# File 'lib/yapra/legacy_plugin/compatible_mode_registry.rb', line 27

def logger
  Yapra::Runtime.logger
end