Method: Roby::Application#find_files

Defined in:
lib/roby/app.rb

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

Enumerates files based on their relative paths in #search_path. The paths 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], a robot name of v3 and a robot type of asguard,

app1/config/v3.rb
app2/config/asguard.rb

Examples:

find_files('config', 'ROBOT.rb', all: true, order: :specific_first)
# returns [app1/config/v3.rb,
#          app2/config/asguard.rb]
find_dirs('tasks', 'ROBOT', all: false, order: :specific_first)
# returns [app1/config/v3.rb]

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (Array<String>)


2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
# File 'lib/roby/app.rb', line 2707

def find_files(*file_path)
    return [] if search_path.empty?

    if file_path.last.kind_of?(Hash)
        options = file_path.pop
    end
    options =
        Kernel.validate_options(options || {}, :all, :order, :path,
                                prioritize_root_paths: false)

    if file_path.empty?
        raise ArgumentError, "no path given"
    end

    # Remove the filename from the complete path
    filename = file_path.pop
    filename = filename.split("/")
    file_path.concat(filename[0..-2])
    filename = filename[-1]

    if filename =~ /ROBOT/ && robot_name
        args = file_path + [options.merge(pattern: filename.gsub("ROBOT", robot_name))]
        robot_name_matches = find_files_in_dirs(*args)

        robot_type_matches = []
        if robot_name != robot_type
            args = file_path + [options.merge(pattern: filename.gsub("ROBOT", robot_type))]
            robot_type_matches = find_files_in_dirs(*args)
        end

        if options[:order] == :specific_first
            result = robot_name_matches + robot_type_matches
        else
            result = robot_type_matches + robot_name_matches
        end
    else
        args = file_path.dup
        args << options.merge(pattern: filename)
        result = find_files_in_dirs(*args)
    end

    orig_path = Pathname.new(File.join(*file_path))
    orig_path += filename
    if orig_path.absolute? && File.file?(orig_path.to_s)
        if options[:order] == :specific_first
            result.unshift orig_path.to_s
        else
            result.push orig_path.to_s
        end
    end

    result
end