Class: ProconBypassMan::Procon::MacroRegistry2
- Inherits:
-
Object
- Object
- ProconBypassMan::Procon::MacroRegistry2
- Defined in:
- lib/procon_bypass_man/procon/macro_registry2.rb
Constant Summary collapse
- PRESETS =
{ null: [], }
Instance Attribute Summary collapse
-
#plugins ⇒ Object
Returns the value of attribute plugins.
Instance Method Summary collapse
- #cleanup_remote_macros! ⇒ Object
-
#initialize ⇒ MacroRegistry2
constructor
A new instance of MacroRegistry2.
- #install_plugin(klass, steps: nil, macro_type: :normal) ⇒ Object
- #load(name, macro_type: :normal, force_neutral_buttons: [], &after_callback_block) ⇒ ProconBypassMan::Procon::Macro
Constructor Details
#initialize ⇒ MacroRegistry2
Returns a new instance of MacroRegistry2.
10 11 12 |
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 10 def initialize self.plugins = ProconBypassMan::Procon::MacroPluginMap.new end |
Instance Attribute Details
#plugins ⇒ Object
Returns the value of attribute plugins.
4 5 6 |
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 4 def plugins @plugins end |
Instance Method Details
#cleanup_remote_macros! ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 38 def cleanup_remote_macros! remote_keys = plugins.original_keys.select { |_, y| y == :remote } remote_keys.each do |remote_key| plugins.delete(remote_key) end plugins end |
#install_plugin(klass, steps: nil, macro_type: :normal) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 14 def install_plugin(klass, steps: nil, macro_type: :normal) if plugins.fetch([klass.to_s.to_sym, macro_type], nil) Kernel.warn "#{klass} macro is already registered" return end plugins.store( [klass.to_s.to_sym, macro_type], ->{ ProconBypassMan::Procon::MacroBuilder.new(steps || klass.steps).build } ) end |
#load(name, macro_type: :normal, force_neutral_buttons: [], &after_callback_block) ⇒ ProconBypassMan::Procon::Macro
28 29 30 31 32 33 34 35 |
# File 'lib/procon_bypass_man/procon/macro_registry2.rb', line 28 def load(name, macro_type: :normal, force_neutral_buttons: [], &after_callback_block) if(steps = PRESETS[name] || plugins.fetch([name.to_s.to_sym, macro_type], nil)&.call) return ProconBypassMan::Procon::Macro.new(name: name, steps: steps.dup, force_neutral_buttons: , &after_callback_block) else warn "installされていないマクロ(#{name})を使うことはできません" return self.load(:null) end end |