Class: Yapra::LegacyPlugin::AdvanceModeRegistry

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

Overview

AdvanceModeRegistry load legacy plugin at one by one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths, pipeline) ⇒ AdvanceModeRegistry

paths

Directory paths which contain legacy plugins.

pipeline

Runtime pipline.



15
16
17
18
19
# File 'lib/yapra/legacy_plugin/advance_mode_registry.rb', line 15

def initialize paths, pipeline
  self.legacy_plugins = {}
  self.plugin_paths = paths.reverse
  self.pipeline = pipeline
end

Instance Attribute Details

#legacy_pluginsObject

Returns the value of attribute legacy_plugins.



9
10
11
# File 'lib/yapra/legacy_plugin/advance_mode_registry.rb', line 9

def legacy_plugins
  @legacy_plugins
end

#pipelineObject

Returns the value of attribute pipeline.



11
12
13
# File 'lib/yapra/legacy_plugin/advance_mode_registry.rb', line 11

def pipeline
  @pipeline
end

#plugin_pathsObject

Returns the value of attribute plugin_paths.



10
11
12
# File 'lib/yapra/legacy_plugin/advance_mode_registry.rb', line 10

def plugin_paths
  @plugin_paths
end

Instance Method Details

#get(module_name) ⇒ Object

load plugin from module name.

example:

registry = Yapra::LegacyPlugin::AdvanceModeRegistry.new(paths, pipeline)
feed_load_plugin = registry.get('Feed::load')


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/yapra/legacy_plugin/advance_mode_registry.rb', line 32

def get module_name
  plugin = legacy_plugins[module_name]
  unless plugin
    plugin_paths.each do |folder|
      file = File.join(folder, (module_name.gsub('::', '/') + '.rb'))
      if File.file?(file)
        plugin = Yapra::LegacyPlugin::Base.new(pipeline, file)
        legacy_plugins[ module_name ] = plugin
        logger.debug "#{module_name} is loaded from #{file}"
        break
      end
    end
  end
  raise "#{module_name} is not registered." unless plugin
  plugin
end

#loggerObject



21
22
23
# File 'lib/yapra/legacy_plugin/advance_mode_registry.rb', line 21

def logger
  Yapra::Runtime.logger
end