Class: MDT::Helpers::Command
- Inherits:
-
Object
- Object
- MDT::Helpers::Command
- Defined in:
- lib/mdt/helpers/command.rb
Overview
A helper class to be used when implementing commands
Class Method Summary collapse
-
.apply_command_modifiers(command, modifiers) ⇒ Object
Finds and applies command modifiers to a command using passed modifiers configuration.
Class Method Details
.apply_command_modifiers(command, modifiers) ⇒ Object
Finds and applies command modifiers to a command using passed modifiers configuration. Arguments:
-
command
- a command or expression to prepend command modifiers to -
modifiers
- an array of modifier configurations - each configuration is a Hash that includes the modifier type and modifier options
Returns:
-
Modified command
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mdt/helpers/command.rb', line 13 def self.apply_command_modifiers(command, modifiers) modifiers.each do |modifier_config| unless modifier_config.has_key?('type') puts 'WARNING: Skipping command modifier because of missing type...' next end modifier_key = modifier_config['type'].split('.').first modifier_value = modifier_config['type'].split('.').last = modifier_config['options'] modifier = MDT::CommandModifiers::Base.descendants.select { |cm| cm.key == modifier_key }.first if modifier == nil puts "WARNING: Could not find a command modifier set with key #{modifier_key}. Check its correctness or install needed MDT modules." next end unless modifier.subkeys.include?(modifier_value) puts "WARNING: Command modifier set with key #{modifier_key} does not have a command modifier with key #{modifier_value}." next end modifier = modifier.new command = modifier.prepend(modifier_value, command, ) end command end |