Class: ProconBypassMan::Procon::ModeRegistry2

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/mode_registry2.rb

Defined Under Namespace

Classes: Mode

Constant Summary collapse

PRESETS =
{
  manual: [],
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModeRegistry2

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

#pluginsObject

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

#presetsObject



43
44
45
# File 'lib/procon_bypass_man/procon/mode_registry2.rb', line 43

def presets
  PRESETS
end