Module: Module::Pluggable
- Defined in:
- lib/module/pluggable.rb
Defined Under Namespace
Classes: Plugins
Constant Summary collapse
- DEFAULT_OPTS =
{ :search_path => "plugins", :except => /_$/, :base_class => nil, }.freeze
Instance Method Summary collapse
-
#pluggable(name = :plugins, o = {}) ⇒ Object
pluggable make the name of instance method returning instance of Module::Pluggable::Plugin.
Instance Method Details
#pluggable(name = :plugins, o = {}) ⇒ Object
pluggable make the name of instance method returning instance of Module::Pluggable::Plugin.
All loaded plugins are in anonymous module, so you can’t access the classes directly, and you can create some plugin-sets without confusing class variables etc.
opts => {
:search_path => name,
:base_class => nil,
:except => /_$/, # not yet
}
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/module/pluggable.rb', line 27 def pluggable(name=:plugins, o={}) opts = DEFAULT_OPTS.merge(o) opts[:search_path] = name ? name.to_s : opts[:name].to_s unless opts[:search_path] class_eval " def \#{name}\n @\#{name} ||= Module::Pluggable::Plugins.new(@@pluggable_opts[:\#{name}])\n end\n\n def self.set_pluggable_opts(name, opts)\n (@@pluggable_opts ||= {})[name] = opts\n end\n EOS\n self.set_pluggable_opts(name, opts)\n (class << self; self; end).instance_eval do\n remove_method(:set_pluggable_opts)\n end\nend\n" |