module Kumogata2::Plugin

Public Class Methods

find_by_ext(ext) click to toggle source
# File lib/kumogata2/plugin.rb, line 18
def find_by_ext(ext)
  plgn = self.plugins.reverse.find do |i|
    i.ext.include?(ext)
  end

  plgn ? plgn.type : nil
end
load_plugins() click to toggle source
# File lib/kumogata2/plugin.rb, line 34
def load_plugins
  plgns = Gem::Specification.find_all.select {|i| i.name =~ /\Akumogata2-plugin-/ }

  plgns.each do |plgns_spec|
    name = plgns_spec.name
    path = File.join(name.split('-', 3))

    begin
      require path
    rescue LoadError => e
      Kumogata2::Logger::Helper.log(:warn, "Cannot load plugin: #{name}: #{e}", color: :yellow)
    end
  end
end
plugin_by_name() click to toggle source
# File lib/kumogata2/plugin.rb, line 26
def plugin_by_name
  @plugins
end
plugins() click to toggle source
# File lib/kumogata2/plugin.rb, line 30
def plugins
  @plugins.map {|_, v| v }
end
register(name, exts, klass) click to toggle source
# File lib/kumogata2/plugin.rb, line 3
def register(name, exts, klass)
  name = name.to_s
  @plugins ||= Hashie::Mash.new

  if @plugins.has_key?(name)
    Kumogata2::Logger::Helper.log(:warn, "Plugin has already been registered: #{name}", color: :yellow)
  end

  @plugins[name] = {
    name: name,
    type: klass,
    ext: exts.map(&:to_s),
  }
end