Class: Gloo::Plugin::ExtManager

Inherits:
Object
  • Object
show all
Defined in:
lib/gloo/plugin/ext_manager.rb

Constant Summary collapse

EXT_FILE =

Constants for extension management

'_ext.rb'

Instance Method Summary collapse

Constructor Details

#initialize(engine) ⇒ ExtManager

Set up the extension manager.



18
19
20
21
22
# File 'lib/gloo/plugin/ext_manager.rb', line 18

def initialize( engine )
  @engine = engine
  @extensions = {}
  @engine.log.debug 'extension manager intialized...'
end

Instance Method Details

#ext_start_file(name) ⇒ Object

Get the start file for the extension.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gloo/plugin/ext_manager.rb', line 34

def ext_start_file name
  root = @engine.settings.ext_path

  unless File.exist?( root )
    @engine.log.error "Extension directory does not exist: #{root}"
    return nil
  end
  
  f = File.join( root, name, name + EXT_FILE )
  unless File.exist?( f )
    @engine.log.error "Extension start file does not exist: #{f}"
    return nil
  end
  
  return f
end

#load_ext(name) ⇒ Object

Load the extension of the given name. The name will correspond with the name of a directory within the gloo extensions directory.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gloo/plugin/ext_manager.rb', line 56

def load_ext( name )
  @engine.log.debug "Loading extension: #{name}"
  fn = ext_start_file name

  unless fn
    @engine.log.error "Extension start file not found for: #{name}"
    return
  end
  
  @extensions[name] = fn
  register_extension name, fn
  @engine.log.debug "Extension loaded: #{name}"
end

#loaded_extensionsObject

Get the loaded extensions.



27
28
29
# File 'lib/gloo/plugin/ext_manager.rb', line 27

def loaded_extensions
  return @extensions
end

#register_extension(name, full_path) ⇒ Object

Give the extension a chance to register its verbs and objects.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/gloo/plugin/ext_manager.rb', line 73

def register_extension( name, full_path )
  require full_path

  class_name = name.capitalize + "Ext"
  @engine.log.debug "Looking for extension to register: #{class_name}"
  begin
    plugin_class = Object.const_get( class_name )
    inst = plugin_class.new
    ext_cb = Callback.new( @engine )
    inst.register( ext_cb )
  rescue NameError
    @engine.log.error "Warning: Could not find class #{class_name} in file #{full_path}"
  end
end