Class: Parlour::Plugin Abstract

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/parlour/plugin.rb

Overview

This class is abstract.

The base class for user-defined RBI generation plugins.

Constant Summary collapse

@@registered_plugins =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Plugin

Returns a new instance of Plugin.



53
# File 'lib/parlour/plugin.rb', line 53

def initialize(options); end

Class Method Details

.inherited(new_plugin) ⇒ void

This method returns an undefined value.

Called automatically by the Ruby interpreter when Parlour::Plugin is subclassed. This registers the new subclass into registered_plugins.

Parameters:

  • new_plugin (Plugin)

    The new plugin.



27
28
29
# File 'lib/parlour/plugin.rb', line 27

def self.inherited(new_plugin)
  registered_plugins[T.must(new_plugin.name)] = new_plugin
end

.registered_plugins{String, Plugin}

Returns all registered plugins, as a hash of their paths to the Parlour::Plugin instances themselves.

Returns:



17
18
19
# File 'lib/parlour/plugin.rb', line 17

def self.registered_plugins
  @@registered_plugins
end

.run_plugins(plugins, generator, allow_failure: true) ⇒ void

This method returns an undefined value.

Runs an array of plugins on a given generator instance.

Parameters:

  • plugins (Array<Plugin>)

    An array of Parlour::Plugin instances.

  • generator (RbiGenerator)

    The RbiGenerator to run the plugins on.

  • allow_failure (Boolean) (defaults to: true)

    Whether to keep running plugins if a plugin throws an exception. If false, the exception is re-raised when caught.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/parlour/plugin.rb', line 39

def self.run_plugins(plugins, generator, allow_failure: true)
  plugins.each do |plugin|
    begin
      puts "=== #{plugin.class.name}"
      generator.current_plugin = plugin
      plugin.generate(generator.root)
    rescue Exception => e
      raise e unless allow_failure
      puts "!!! This plugin threw an exception: #{e}"
    end
  end
end

Instance Method Details

#generate(root) ⇒ void

This method is abstract.

This method returns an undefined value.

Plugin subclasses should redefine this method and do their RBI generation inside it.

Parameters:



62
# File 'lib/parlour/plugin.rb', line 62

def generate(root); end