module DTK::Client::CLI::DirectoryParser::FileSystem::MultipleMatches
Public Class Methods
input_types()
click to toggle source
# File lib/cli/directory_parser/file_system.rb, line 138 def self.input_types { 'module' => DTK::DSL::FileType::CommonModule::DSLFile::Top, 'service' => DTK::DSL::FileType::ServiceInstance::DSLFile::Top::Hidden # 'service' => DTK::DSL::FileType::ServiceInstance::DSLFile::Top } end
rank_based_on_input()
click to toggle source
# File lib/cli/directory_parser/file_system.rb, line 134 def self.rank_based_on_input input_types[ARGV.first] end
ranking_for_types()
click to toggle source
lower is preferred
# File lib/cli/directory_parser/file_system.rb, line 126 def self.ranking_for_types @ranking_for_types ||= { DTK::DSL::FileType::CommonModule::DSLFile::Top => 2, DTK::DSL::FileType::ServiceInstance::DSLFile::Top => 1, DTK::DSL::FileType::ServiceInstance::DSLFile::Top::Hidden => 0 } end
resolve(matches)
click to toggle source
# File lib/cli/directory_parser/file_system.rb, line 103 def self.resolve(matches) # first try to make decission based on user's input e.g. 'dtk module ...' or 'dtk service ...' if input_rank = rank_based_on_input top_match = matches.select { |match| match.first == input_rank } return top_match.first if top_match && !top_match.empty? end augmented_matches = matches.map { |match| { match: match, ranking: type_ranking(match[0]) } } not_treated_types = augmented_matches.select { |aug_match| aug_match[:ranking].nil? } fail Error, "No ranking for types: #{not_treated_types.map { |aug_match| aug_match[:match][0] }.join(', ')}" unless not_treated_types.empty? ndx_matches = {} augmented_matches.each { |aug_match| (ndx_matches[aug_match[:ranking]] ||= []) << aug_match[:match] } top_matches = ndx_matches[ndx_matches.keys.sort.first] fail Error, "Cannot choice between types: #{top_matches.map{ |match| match[0] }.join(', ')}" if top_matches.size > 1 top_matches.first end
type_ranking(type)
click to toggle source
# File lib/cli/directory_parser/file_system.rb, line 121 def self.type_ranking(type) ranking_for_types[type] end