Module: RVM::Plugin

Overview

Plugin

Plugins have to include this module.

IMPORTANT: use extend for this module.

Example: see PluginHost.

Instance Method Summary collapse

Instance Method Details

#helper(*helpers) ⇒ Object

Require some helper files.

Example:

class MyPlugin < PluginHost::BaseClass
   register_for :my_id
   helper :my_helper

The above example loads the file myplugin/my_helper.rb relative to the file in which MyPlugin was defined.



310
311
312
313
314
# File 'lib/rvm/plugin.rb', line 310

def helper *helpers
  for helper in helpers
    self::PLUGIN_HOST.require_helper plugin_id, helper.to_s
  end
end

#included(mod) ⇒ Object



274
275
276
# File 'lib/rvm/plugin.rb', line 274

def included mod
  warn "#{name} should not be included. Use extend."
end

#plugin_host(host = nil) ⇒ Object

The host for this Plugin class.



291
292
293
294
295
296
297
298
# File 'lib/rvm/plugin.rb', line 291

def plugin_host host = nil
  if host and not host.is_a? PluginHost
    raise ArgumentError,
      "PluginHost expected, but #{host.class} given."
  end
  self.const_set :PLUGIN_HOST, host if host
  self::PLUGIN_HOST
end

#plugin_idObject

Returns the pulgin id used by the engine.



317
318
319
# File 'lib/rvm/plugin.rb', line 317

def plugin_id
  name[/[\w_]+$/].downcase
end

#register_for(*ids) ⇒ Object

Register this class for the given langs. Example:

class MyPlugin < PluginHost::BaseClass
  register_for :my_id
  ...
end

See PluginHost.register.



286
287
288
# File 'lib/rvm/plugin.rb', line 286

def register_for *ids
  plugin_host.register self, *ids
end