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 =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Plugin

Returns a new instance of Plugin.



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

def initialize(options); end

Instance Attribute Details

#strictnessObject

The strictness level which this plugin would prefer the generated RBI uses. If other plugins request different strictness levels, then the lowest strictness will be used, meaning there is no guarantee that this level will be used.



70
71
72
# File 'lib/parlour/plugin.rb', line 70

def strictness
  @strictness
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
30
# File 'lib/parlour/plugin.rb', line 27

def self.inherited(new_plugin)
  Debugging.debug_puts(self, 'Registered')
  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.



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

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:



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

def generate(root); end