Class: Decidim::Ai::StrategyRegistry
- Inherits:
-
Object
- Object
- Decidim::Ai::StrategyRegistry
- Defined in:
- lib/decidim/ai/strategy_registry.rb
Defined Under Namespace
Classes: StrategyAlreadyRegistered
Instance Attribute Summary collapse
-
#strategies ⇒ Object
readonly
Returns the value of attribute strategies.
Instance Method Summary collapse
- #for(name) ⇒ Object
-
#initialize ⇒ StrategyRegistry
constructor
A new instance of StrategyRegistry.
- #register_analyzer(name:, strategy:, options: {}) ⇒ Object
Constructor Details
#initialize ⇒ StrategyRegistry
Returns a new instance of StrategyRegistry.
11 12 13 |
# File 'lib/decidim/ai/strategy_registry.rb', line 11 def initialize @strategies = [] end |
Instance Attribute Details
#strategies ⇒ Object (readonly)
Returns the value of attribute strategies.
9 10 11 |
# File 'lib/decidim/ai/strategy_registry.rb', line 9 def strategies @strategies end |
Instance Method Details
#for(name) ⇒ Object
27 28 29 |
# File 'lib/decidim/ai/strategy_registry.rb', line 27 def for(name) strategies.select { |k, _v| k.name == name }.first end |
#register_analyzer(name:, strategy:, options: {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/decidim/ai/strategy_registry.rb', line 15 def register_analyzer(name:, strategy:, options: {}) if self.for(name).present? raise( StrategyAlreadyRegistered, "There is a strategy already registered with the name `:#{name}`" ) end = { name: }.merge() strategies << strategy.new() end |