Module: Module::Pluggable

Module::Pluggable (Module)

In files
lib/module/pluggable.rb

Methods

Classes and Modules

Class Module::Pluggable::Plugins

Constants

DEFAULT_OPTS
{ :search_path => "plugins", :except => /_$/, :base_class => nil, }.freeze

Public Instance methods

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
    }
    # File lib/module/pluggable.rb, line 27
27:         def pluggable(name=:plugins, o={})
28:                 opts = DEFAULT_OPTS.merge(o)
29:                 opts[:search_path] = name ? name.to_s : opts[:name].to_s unless opts[:search_path]
30: 
31:                 class_eval "def \#{name}\n@\#{name} ||= Module::Pluggable::Plugins.new(@@pluggable_opts[:\#{name}])\nend\n\ndef self.set_pluggable_opts(name, opts)\n(@@pluggable_opts ||= {})[name] = opts\nend\n"
32:                 self.set_pluggable_opts(name, opts)
33:                 (class << self; self; end).instance_eval do
34:                         remove_method(:set_pluggable_opts)
35:                 end
36:         end