Module: Lennarb::Plugin

Defined in:
lib/lennarb/plugin.rb

Defined Under Namespace

Classes: Error

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.registryObject (readonly)

Returns the value of attribute registry.



11
12
13
# File 'lib/lennarb/plugin.rb', line 11

def registry
  @registry
end

Class Method Details

.load(name) ⇒ Object



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

def load(name)
  registry[name.to_sym] || raise(Error, "Plugin #{name} not found")
end

.load_defaults!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lennarb/plugin.rb', line 21

def load_defaults!
  return if @defaults_loaded

  # 1. Register default plugins
  plugins_path = File.expand_path('plugins', __dir__)
  load_plugins_from_directory(plugins_path)

  # # 2. Register custom plugins
  ENV.fetch('LENNARB_PLUGINS_PATH', nil)&.split(File::PATH_SEPARATOR)&.each do |path|
    load_plugins_from_directory(path)
  end

  @defaults_loaded = true
end

.load_defaults?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/lennarb/plugin.rb', line 36

def load_defaults?
  ENV.fetch('LENNARB_AUTO_LOAD_DEFAULTS', 'true') == 'true'
end

.register(name, mod) ⇒ Object



13
14
15
# File 'lib/lennarb/plugin.rb', line 13

def register(name, mod)
  registry[name.to_sym] = mod
end