Class: ProconBypassMan::Procon::ModeRegistry2
- Inherits:
-
Object
- Object
- ProconBypassMan::Procon::ModeRegistry2
- Defined in:
- lib/procon_bypass_man/procon/mode_registry2.rb
Defined Under Namespace
Classes: Mode
Constant Summary collapse
- PRESETS =
{ manual: [], }
Instance Attribute Summary collapse
-
#plugins ⇒ Object
Returns the value of attribute plugins.
Instance Method Summary collapse
-
#initialize ⇒ ModeRegistry2
constructor
A new instance of ModeRegistry2.
- #install_plugin(klass) ⇒ Object
- #load(name) ⇒ Object
- #presets ⇒ Object
Constructor Details
#initialize ⇒ ModeRegistry2
Returns a new instance of ModeRegistry2.
27 28 29 |
# File 'lib/procon_bypass_man/procon/mode_registry2.rb', line 27 def initialize self.plugins = {} end |
Instance Attribute Details
#plugins ⇒ Object
Returns the value of attribute plugins.
21 22 23 |
# File 'lib/procon_bypass_man/procon/mode_registry2.rb', line 21 def plugins @plugins end |
Instance Method Details
#install_plugin(klass) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/procon_bypass_man/procon/mode_registry2.rb', line 31 def install_plugin(klass) if plugins[klass.to_s.to_sym] raise "#{klass} mode is already registered" end plugins[klass.to_s.to_sym] = ->{ klass.binaries } end |
#load(name) ⇒ Object
38 39 40 41 |
# File 'lib/procon_bypass_man/procon/mode_registry2.rb', line 38 def load(name) b = PRESETS[name] || plugins[name]&.call || raise("#{name} is unknown mode") Mode.new(name: name, binaries: b.dup) end |
#presets ⇒ Object
43 44 45 |
# File 'lib/procon_bypass_man/procon/mode_registry2.rb', line 43 def presets PRESETS end |