Module: Ramaze::Plugin

Defined in:
lib/ramaze/plugin.rb

Constant Summary collapse

PLUGIN_LIST =
Set.new
EXTS =
%w[rb so bundle]
PATH =
[]
POOL =
[]

Class Method Summary collapse

Class Method Details

.add_path(path) ⇒ Object



38
39
40
41
# File 'lib/ramaze/plugin.rb', line 38

def add_path(path)
  PATH.unshift(File.expand_path(path))
  PATH.uniq!
end

.add_pool(pool) ⇒ Object



31
32
33
34
# File 'lib/ramaze/plugin.rb', line 31

def add_pool(pool)
  POOL.unshift(pool)
  POOL.uniq!
end

.glob(name = '*') ⇒ Object



61
62
63
# File 'lib/ramaze/plugin.rb', line 61

def glob(name = '*')
  "{#{paths.join(',')}}/plugin/#{name}.{#{EXTS.join(',')}}"
end

.load(name, options) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/ramaze/plugin.rb', line 46

def load(name, options)
  name = name.to_s
  try_require(name.snake_case)
  PLUGIN_LIST << [name, const_get(name.camel_case), options]
rescue Exception => exception
  Log.error(exception)
  raise LoadError, "Plugin #{name} not found"
end

.pathsObject



65
66
67
# File 'lib/ramaze/plugin.rb', line 65

def paths
  PATH
end

.setupObject



19
20
21
22
23
# File 'lib/ramaze/plugin.rb', line 19

def setup
  PLUGIN_LIST.each do |name, const, options|
    const.setup(options) if const.respond_to?(:setup)
  end
end

.teardownObject



25
26
27
28
29
# File 'lib/ramaze/plugin.rb', line 25

def teardown
  PLUGIN_LIST.each do |name, const, options|
    const.teardown if const.respond_to?(:teardown)
  end
end

.try_require(name) ⇒ Object



55
56
57
58
59
# File 'lib/ramaze/plugin.rb', line 55

def try_require(name)
  found = Dir[glob(name)].first
  require(File.expand_path(found)) if found
rescue LoadError
end