lib/sfn/utils/path_selector.rb in sfn-3.0.28 vs lib/sfn/utils/path_selector.rb in sfn-3.0.30
- old
+ new
@@ -24,79 +24,78 @@
# @option opts [Array<String>] :ignore_directories directory names
# @option opts [String] :directories_name title for directories
# @option opts [String] :files_name title for files
# @option opts [String] :filter_prefix only return results matching filter
# @return [String] file path
- def prompt_for_file(directory, opts={})
+ def prompt_for_file(directory, opts = {})
file_list = Dir.glob(File.join(directory, '**', '**', '*')).find_all do |file|
File.file?(file)
end
- if(opts[:filter_prefix])
+ if opts[:filter_prefix]
file_list = file_list.find_all do |file|
file.start_with?(options[:filter_prefix])
end
end
directories = file_list.map do |file|
File.dirname(file)
end.uniq
files = file_list.find_all do |path|
path.sub(directory, '').split('/').size == 2
end
- if(opts[:ignore_directories])
+ if opts[:ignore_directories]
directories.delete_if do |dir|
opts[:ignore_directories].include?(File.basename(dir))
end
end
- if(directories.empty? && files.empty?)
+ if directories.empty? && files.empty?
ui.fatal 'No formation paths discoverable!'
else
output = ['Please select an entry']
output << '(or directory to list):' unless directories.empty?
ui.info output.join(' ')
output.clear
idx = 1
valid = {}
- unless(directories.empty?)
+ unless directories.empty?
output << ui.color("#{opts.fetch(:directories_name, 'Directories')}:", :bold)
directories.each do |dir|
valid[idx] = {:path => dir, :type => :directory}
output << [idx, humanize_path_basename(dir)]
idx += 1
end
end
- unless(files.empty?)
+ unless files.empty?
output << ui.color("#{opts.fetch(:files_name, 'Files')}:", :bold)
files.each do |file|
valid[idx] = {:path => file, :type => :file}
output << [idx, humanize_path_basename(file)]
idx += 1
end
end
max = idx.to_s.length
output.map! do |o|
- if(o.is_a?(Array))
+ if o.is_a?(Array)
" #{o.first}.#{' ' * (max - o.first.to_s.length)} #{o.last}"
else
o
end
end
ui.info "#{output.join("\n")}\n"
response = ui.ask_question('Enter selection: ').to_i
- unless(valid[response])
+ unless valid[response]
ui.fatal 'How about using a real value'
exit 1
else
entry = valid[response.to_i]
- if(entry[:type] == :directory)
+ if entry[:type] == :directory
prompt_for_file(entry[:path], opts)
elsif Pathname(entry[:path]).absolute?
entry[:path]
else
"/#{entry[:path]}"
end
end
end
end
-
end
end
end