Class: JIJI::Plugin::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/jiji/plugin/plugin_loader.rb

Overview

プラグインローダー

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns a new instance of Loader.



29
30
31
# File 'lib/jiji/plugin/plugin_loader.rb', line 29

def initialize
  @loaded = Set.new
end

Instance Attribute Details

#server_loggerObject

Returns the value of attribute server_logger.



53
54
55
# File 'lib/jiji/plugin/plugin_loader.rb', line 53

def server_logger
  @server_logger
end

Instance Method Details

#loadObject

プラグインをロードする。



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/jiji/plugin/plugin_loader.rb', line 33

def load
  ($: + Gem.latest_load_paths).each {|dir|
    plugin = File.expand_path "#{dir}/jiji_plugin.rb"
    next unless File.exist? plugin
    next if @loaded.include?( plugin )
    begin 
      Kernel.load plugin
      server_logger.info( "plugin loaded. plugin_path=#{plugin}" ) if server_logger
      @loaded << plugin
    rescue Exception
      if server_logger
        server_logger.error( "plugin load failed. plugin_path=#{plugin}" ) 
        server_logger.error($!)  
      else
        puts "plugin load failed. plugin_path=#{plugin}"
        puts ([$!.to_s] + $!.backtrace).join("\n      ")
      end
    end
  }
end