Class: RubyCoded::Plugins::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_coded/plugins/registry.rb

Overview

Stores registered plugins and provides access to their extensions. Used by Chat::App at boot time to wire everything together.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



10
11
12
# File 'lib/ruby_coded/plugins/registry.rb', line 10

def initialize
  @plugins = []
end

Instance Attribute Details

#pluginsObject (readonly)

Returns the value of attribute plugins.



8
9
10
# File 'lib/ruby_coded/plugins/registry.rb', line 8

def plugins
  @plugins
end

Instance Method Details

#all_command_descriptionsObject



61
62
63
# File 'lib/ruby_coded/plugins/registry.rb', line 61

def all_command_descriptions
  @plugins.each_with_object({}) { |p, h| h.merge!(p.command_descriptions) }
end

#all_commandsObject



57
58
59
# File 'lib/ruby_coded/plugins/registry.rb', line 57

def all_commands
  @plugins.each_with_object({}) { |p, h| h.merge!(p.commands) }
end

#apply_extensions!(state_class:, input_handler_class:, renderer_class:, command_handler_class:) ⇒ Object

Includes all plugin modules into the target classes in one pass.



66
67
68
69
70
71
# File 'lib/ruby_coded/plugins/registry.rb', line 66

def apply_extensions!(state_class:, input_handler_class:, renderer_class:, command_handler_class:)
  safe_include(state_class, state_extensions)
  safe_include(input_handler_class, input_extensions)
  safe_include(renderer_class, renderer_extensions)
  safe_include(command_handler_class, command_handler_extensions)
end

#command_handler_extensionsObject



33
34
35
# File 'lib/ruby_coded/plugins/registry.rb', line 33

def command_handler_extensions
  @plugins.filter_map(&:command_handler_extension)
end

#input_extensionsObject



25
26
27
# File 'lib/ruby_coded/plugins/registry.rb', line 25

def input_extensions
  @plugins.filter_map(&:input_extension)
end

#input_handler_configsObject

Returns an array of { method: Symbol } for each plugin that contributes an input handler hook.



39
40
41
42
43
44
45
# File 'lib/ruby_coded/plugins/registry.rb', line 39

def input_handler_configs
  @plugins.filter_map do |plugin|
    next unless plugin.input_handler_method

    { method: plugin.input_handler_method }
  end
end

#register(plugin_class) ⇒ Object



14
15
16
17
18
19
# File 'lib/ruby_coded/plugins/registry.rb', line 14

def register(plugin_class)
  validate!(plugin_class)
  return if @plugins.include?(plugin_class)

  @plugins << plugin_class
end

#render_configsObject

Returns an array of { method: Symbol } for each plugin that contributes a render overlay.



49
50
51
52
53
54
55
# File 'lib/ruby_coded/plugins/registry.rb', line 49

def render_configs
  @plugins.filter_map do |plugin|
    next unless plugin.render_method

    { method: plugin.render_method }
  end
end

#renderer_extensionsObject



29
30
31
# File 'lib/ruby_coded/plugins/registry.rb', line 29

def renderer_extensions
  @plugins.filter_map(&:renderer_extension)
end

#state_extensionsObject



21
22
23
# File 'lib/ruby_coded/plugins/registry.rb', line 21

def state_extensions
  @plugins.filter_map(&:state_extension)
end