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
- .add_path(path) ⇒ Object
- .add_pool(pool) ⇒ Object
- .glob(name = '*') ⇒ Object
- .load(name, options) ⇒ Object
- .paths ⇒ Object
- .setup ⇒ Object
- .teardown ⇒ Object
- .try_require(name) ⇒ Object
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.(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, ) 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 |
.setup ⇒ Object
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 |
.teardown ⇒ Object
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 |
.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.(found)) if found rescue LoadError end |