Class: RubyCoded::Plugins::Registry
- Inherits:
-
Object
- Object
- RubyCoded::Plugins::Registry
- 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
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
- #all_command_descriptions ⇒ Object
- #all_commands ⇒ Object
-
#apply_extensions!(state_class:, input_handler_class:, renderer_class:, command_handler_class:) ⇒ Object
Includes all plugin modules into the target classes in one pass.
- #command_handler_extensions ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #input_extensions ⇒ Object
-
#input_handler_configs ⇒ Object
Returns an array of { method: Symbol } for each plugin that contributes an input handler hook.
- #register(plugin_class) ⇒ Object
-
#render_configs ⇒ Object
Returns an array of { method: Symbol } for each plugin that contributes a render overlay.
- #renderer_extensions ⇒ Object
- #state_extensions ⇒ Object
Constructor Details
#initialize ⇒ Registry
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
#plugins ⇒ Object (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_descriptions ⇒ Object
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_commands ⇒ Object
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_extensions ⇒ Object
33 34 35 |
# File 'lib/ruby_coded/plugins/registry.rb', line 33 def command_handler_extensions @plugins.filter_map(&:command_handler_extension) end |
#input_extensions ⇒ Object
25 26 27 |
# File 'lib/ruby_coded/plugins/registry.rb', line 25 def input_extensions @plugins.filter_map(&:input_extension) end |
#input_handler_configs ⇒ Object
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_configs ⇒ Object
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_extensions ⇒ Object
29 30 31 |
# File 'lib/ruby_coded/plugins/registry.rb', line 29 def renderer_extensions @plugins.filter_map(&:renderer_extension) end |
#state_extensions ⇒ Object
21 22 23 |
# File 'lib/ruby_coded/plugins/registry.rb', line 21 def state_extensions @plugins.filter_map(&:state_extension) end |