Class: Zoom::Profile::Find

Inherits:
Zoom::Profile show all
Defined in:
lib/zoom/profile/find.rb

Instance Attribute Summary

Attributes inherited from Zoom::Profile

#exts, #files, #format_flags, #regex, #taggable

Instance Method Summary collapse

Methods inherited from Zoom::Profile

#after, #before, #class_name, #flags, from_json, #grep_like_tags?, #name, #only_exts_and_files, profile_by_name, subclasses, #to_s, #tool

Constructor Details

#initialize(n = nil, t = nil, f = nil, b = nil, a = nil) ⇒ Find

Returns a new instance of Find.



30
31
32
33
34
35
# File 'lib/zoom/profile/find.rb', line 30

def initialize(n = nil, t = nil, f = nil, b = nil, a = nil)
    a = "-print" if (a.nil? || a.empty?)
    f ||= ""
    t ||= "find"
    super(n, t, f, b, a)
end

Instance Method Details

#exe(header) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/zoom/profile/find.rb', line 4

def exe(header)
    cmd = [
        before,
        tool,
        header["paths"],
        flags,
        header["translated"],
        header["args"],
        header["regex"],
        after
    ].join(" ").strip

    if (header.has_key?("debug") && header["debug"])
        puts(cmd)
        return ""
    else
        return %x(#{cmd})
    end
end

#grep_like_format_flags(all = false) ⇒ Object



24
25
26
27
28
# File 'lib/zoom/profile/find.rb', line 24

def grep_like_format_flags(all = false)
    super
    @grep_like_tags = false
    @taggable = true
end

#preprocess(header) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zoom/profile/find.rb', line 37

def preprocess(header)
    # If additional args are passed, then assume regex is actually
    # an arg
    if (!header["args"].empty?)
        header["args"] += " #{header["regex"]}"
        header["regex"] = ""
    end

    # If regex was provided then assume it's an iregex search
    if (!header["regex"].empty?)
        header["regex"] = [
            "-regextype posix-extended",
            "-iregex \".*#{header["regex"]}.*\""
        ].join(" ")
    end

    return header
end

#translate(from) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/zoom/profile/find.rb', line 56

def translate(from)
    to = Array.new
    from.each do |flag, value|
        case flag
        when "follow"
            to.push("-L")
        when "ignore"
            value.each do |v|
                to.push("-name \"#{v}\" -prune -o")
            end
        end
    end
    return to.join(" ")
end