Method: Roby::Application#find_files_in_dirs

Defined in:
lib/roby/app.rb

#find_files_in_dirs(*path, options) ⇒ Array<String>

Enumerates the files that are present in subdirectories of paths in #search_path. The subdirectories are resolved using File.join(*path) If one of the elements of the path is the string ‘ROBOT’, it gets replaced by the robot name and type.

Given a search dir of [app1, app2]

app1/models/tasks/goto.rb
app1/models/tasks/v3/goto.rb
app2/models/tasks/asguard/goto.rb

Examples:

find_files_in_dirs('tasks', 'ROBOT', all: true, order: :specific_first)
# returns [app1/models/tasks/v3/goto.rb,
#          app2/models/tasks/asguard/goto.rb,
#          app1/models/tasks/goto.rb]
find_files_in_dirs('tasks', 'ROBOT', all: false, order: :specific_first)
# returns [app1/models/tasks/v3/goto.rb,

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (Array<String>)


2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
# File 'lib/roby/app.rb', line 2637

def find_files_in_dirs(*dir_path)
    return [] if search_path.empty?

    Application.debug { "find_files_in_dirs(#{dir_path.map(&:inspect).join(', ')})" }
    if dir_path.last.kind_of?(Hash)
        options = dir_path.pop
    end
    options = Kernel.validate_options(
        options || {},
        :all, :order, :path,
        prioritize_root_paths: false,
        pattern: Regexp.new("")
    )

    dir_search = dir_path.dup
    dir_search << {
        all: true, order: options[:order], path: options[:path],
        prioritize_root_paths: options[:prioritize_root_paths]
    }
    search_path = find_dirs(*dir_search)

    result = []
    search_path.each do |dirname|
        Application.debug { "  dir: #{dirname}" }
        Dir.new(dirname).each do |file_name|
            file_path = File.join(dirname, file_name)
            Application.debug { "    file: #{file_path}" }
            if File.file?(file_path) && options[:pattern] === file_name
                Application.debug "      added"
                result << file_path
            end
        end
        break unless options[:all]
    end
    result
end