Class: RuGUI::Plugin::Location

Inherits:
Object
  • Object
show all
Includes:
LogSupport
Defined in:
lib/rugui/plugin/loader.rb

Overview

This class is a representation of RuGUI plugins.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogSupport

included, #logger

Constructor Details

#initialize(dir) ⇒ Location

Returns a new instance of Location.



48
49
50
51
# File 'lib/rugui/plugin/loader.rb', line 48

def initialize(dir)
  self.dir = dir
  self.plugin_name = dir.split(File::SEPARATOR).last
end

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



43
44
45
# File 'lib/rugui/plugin/loader.rb', line 43

def dir
  @dir
end

#loadedObject

Returns the value of attribute loaded.



44
45
46
# File 'lib/rugui/plugin/loader.rb', line 44

def loaded
  @loaded
end

#plugin_nameObject

Returns the value of attribute plugin_name.



42
43
44
# File 'lib/rugui/plugin/loader.rb', line 42

def plugin_name
  @plugin_name
end

Instance Method Details

#loadObject

Load plugins.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rugui/plugin/loader.rb', line 54

def load
  $LOAD_PATH.unshift(File.join(self.dir, "lib")) if File.directory?(self.dir)
  $LOAD_PATH.uniq!

  init_file = File.expand_path(File.join(self.dir, "init.rb"))
  if File.exist?(init_file)
    require_for init_file
  else
    logger.warn "The init file for (#{self.plugin_name}) was not found."
  end
end

#loaded?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/rugui/plugin/loader.rb', line 72

def loaded?
  self.loaded ||= false
end

#require_for(init_file) ⇒ Object



66
67
68
69
70
# File 'lib/rugui/plugin/loader.rb', line 66

def require_for(init_file)
  require init_file
rescue Exception
  logger.error "An error occurred while loading #{self.plugin_name}. Checks its init file: #{$!}"
end