Class: Standard::Plugin::DeterminesClassConstant

Inherits:
Object
  • Object
show all
Defined in:
lib/standard/plugin/determines_class_constant.rb

Instance Method Summary collapse

Instance Method Details

#call(plugin_name, user_config) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/standard/plugin/determines_class_constant.rb', line 4

def call(plugin_name, user_config)
  require_plugin(user_config["require_path"])

  if (constant_name = user_config["plugin_class_name"])
    begin
      Kernel.const_get(constant_name)
    rescue
      raise "Failed while configuring plugin `#{plugin_name}': no constant with name `#{constant_name}' was found"
    end
  else
    begin
      Kernel.const_get(Gem.loaded_specs[plugin_name].["default_lint_roller_plugin"])
    rescue LoadError, StandardError
      raise <<~MSG
        Failed loading plugin `#{plugin_name}' because we couldn't determine
        the corresponding plugin class to instantiate.

        Standard plugin class names must either be:

          - If the plugin is a gem, defined in the gemspec as `default_lint_roller_plugin'

            spec.metadata["default_lint_roller_plugin"] = "MyModule::Plugin"

          - Set in YAML as `plugin_class_name'; example:

            plugins:
              - incomplete:
                  require_path: my_module/plugin
                  plugin_class_name: "MyModule::Plugin"
      MSG
    end

  end
end