Sha256: 0d865e3cca30111b1e0fa064db97f72a9c3bc2120257187a1091b7729f3aec28

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

require 'pathname'
require 'yapra/legacy_plugin'

module Yapra::LegacyPlugin
  class CompatibleModeRegistry
    attr_accessor :legacy_plugins
      
    def initialize paths, pipeline
      self.legacy_plugins = {}
      
      paths.each do |folder|
        Pathname.glob(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
    
    def logger
      Yapra::Runtime.logger
    end
    
    def get module_name
      plugin = legacy_plugins[module_name]
      raise "#{module_name} is not registered." unless plugin
      plugin
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yapra-0.1.0 lib/yapra/legacy_plugin/compatible_mode_registry.rb