Module: UltraCommandLine::Manager::Processors
- Includes:
- Commands
- Included in:
- Base
- Defined in:
- lib/ultra_command_line/manager/processors.rb
Constant Summary
collapse
- MANDATORY_PROCESSOR_METHODS =
%i[check_params execute].freeze
Instance Attribute Summary
Attributes included from Commands
#commands
Instance Method Summary
collapse
Methods included from Commands
#aliases_consistent?, #cmd_line_args_for_command, #command, #command_by_alias, #root_command
#cmd_line_args, #cmd_line_args=
Instance Method Details
#clear_processors ⇒ Object
34
35
36
|
# File 'lib/ultra_command_line/manager/processors.rb', line 34
def clear_processors
@processors_hash = nil
end
|
#processor ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/ultra_command_line/manager/processors.rb', line 38
def processor
processor_candidates = processors_hash.fetch(command(cmd_line_args).name, []) .select do |processor|
processor.check_params command.cmd_line_args
end
raise UltraCommandLine::Error, 'No processor found for this command line' if processor_candidates.empty?
raise UltraCommandLine::Error, 'Too many possible processors' unless processor_candidates.size == 1
processor_candidates.first
end
|
#processors(for_command: nil) ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/ultra_command_line/manager/processors.rb', line 10
def processors(for_command: nil)
if for_command.nil?
processors_hash.values.inject([]) do |res, value|
res.concat value
res
end .uniq
else
processors_hash[for_command]
end
end
|
#register_processor(command_name_or_command, processor) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/ultra_command_line/manager/processors.rb', line 21
def register_processor(command_name_or_command, processor)
verify_processor_implementation processor
if processors.include? processor
msg = 'Trying to insert a processor already registered: %s' % [processor.inspect]
UltraCommandLine.logger.debug msg
end
command = command_name_or_command_to_command command_name_or_command
processors_hash[command.name] ||= []
processors_hash[command.name] << processor
command_name = command.name.empty? ? 'Root' : "#{command.name}"
UltraCommandLine.logger.debug "Registered Processor #{processor.inspect} to '#{command_name}' command"
end
|