Module: Ramaze::Plugin
- Defined in:
- lib/ramaze/plugin.rb
Constant Summary
- PLUGIN_LIST =
Set.new
- EXTS =
%w[rb so bundle]
- PATH =
[]
- POOL =
[]
Instance Method Summary (collapse)
- - (Object) add_path(path)
- - (Object) add_pool(pool)
- - (Object) glob(name = '*')
- - (Object) load(name, options)
- - (Object) paths
- - (Object) setup
- - (Object) teardown
- - (Object) try_require(name)
Instance Method Details
- (Object) add_path(path)
38 39 40 41 |
# File 'lib/ramaze/plugin.rb', line 38 def add_path(path) PATH.unshift(File.(path)) PATH.uniq! end |
- (Object) add_pool(pool)
31 32 33 34 |
# File 'lib/ramaze/plugin.rb', line 31 def add_pool(pool) POOL.unshift(pool) POOL.uniq! end |
- (Object) glob(name = '*')
61 62 63 |
# File 'lib/ramaze/plugin.rb', line 61 def glob(name = '*') "{#{paths.join(',')}}/plugin/#{name}.{#{EXTS.join(',')}}" end |
- (Object) load(name, options)
46 47 48 49 50 51 52 53 |
# File 'lib/ramaze/plugin.rb', line 46 def load(name, ) name = name.to_s try_require(name.snake_case) PLUGIN_LIST << [name, const_get(name.camel_case), ] rescue Exception => exception Log.error(exception) raise LoadError, "Plugin #{name} not found" end |
- (Object) paths
65 66 67 |
# File 'lib/ramaze/plugin.rb', line 65 def paths PATH end |
- (Object) setup
19 20 21 22 23 |
# File 'lib/ramaze/plugin.rb', line 19 def setup PLUGIN_LIST.each do |name, const, | const.setup() if const.respond_to?(:setup) end end |
- (Object) teardown
25 26 27 28 29 |
# File 'lib/ramaze/plugin.rb', line 25 def teardown PLUGIN_LIST.each do |name, const, | const.teardown if const.respond_to?(:teardown) end end |
- (Object) try_require(name)
55 56 57 58 59 |
# File 'lib/ramaze/plugin.rb', line 55 def try_require(name) found = Dir[glob(name)].first require(File.(found)) if found rescue LoadError end |