Class: UWA::Plugin

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/uwa/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

Returns a new instance of Plugin.



13
14
15
# File 'lib/uwa/plugin.rb', line 13

def initialize
	@list = {}
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



11
12
13
# File 'lib/uwa/plugin.rb', line 11

def list
  @list
end

Class Method Details

.method_missing(name, *args) ⇒ Object



7
8
9
# File 'lib/uwa/plugin.rb', line 7

def self.method_missing(name, *args)
	self.instance.send(name, *args)
end

Instance Method Details

#loadObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/uwa/plugin.rb', line 17

def load
	return @list unless @list.empty?

	sdir = File.join(Gem.dir, "specifications")
	gems = Gem::SourceIndex.from_installed_gems(sdir)
	needs = {"uwa" => false}
	gems.each do |path, gem|
		next if @list.has_key? gem.name
		check = needs.dup
		gem.dependencies.each do |dep|
			if check.has_key? dep.name
				check[dep.name] = !check[dep.name]
			end
		end
		if (check.select {|name,test| !test}).length == 0
			gem_dir = File.join(Gem.dir, "gems", path)
			file = File.join(gem_dir, "lib", gem.name, "widget.rb")
			before = UWA::Widget.constants rescue []
			require file
			UWA::Server.log(:info, "Load plugin #{gem.name.inspect} v#{gem.version}")
			after = UWA::Widget.constants
			@list[gem.name] = { 
				:base => gem_dir, 
				:class => UWA::Widget.const_get((after - before).first.to_sym),
				:script => Dir[File.join(gem_dir, 'resources', '*.js')],
				:css => Dir[File.join(gem_dir, 'resources', '*.css')]
			}
		end
	end
	@list
end