Class: Zoom::ProfileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/zoom/profile_manager.rb

Constant Summary collapse

@@ranking =
[
    ["rg", "Zoom::Profile::Rg"],
    ["ag", "Zoom::Profile::Ag"],
    ["grep", "Zoom::Profile::Grep"],
    ["pt", "Zoom::Profile::Pt"],
    ["ack", "Zoom::Profile::Ack"],
    ["ack-grep", "Zoom::Profile::Ack"],
    ["find", "Zoom::Profile::Find"]
]
@@tool =
nil

Class Method Summary collapse

Class Method Details

.class_by_tool(t) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/zoom/profile_manager.rb', line 16

def self.class_by_tool(t)
    found = @@ranking.select do |tool, clas|
        t == tool
    end
    return found[0][1] if (!found.empty?)
    return nil
end

.default_classObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zoom/profile_manager.rb', line 24

def self.default_class
    if (@@tool && ScoobyDoo.where_are_you(@@tool))
        return class_by_tool(@@tool)
    end

    @@ranking.each do |tool, clas|
        return clas if (ScoobyDoo.where_are_you(tool))
    end

    return nil # shouldn't happen
end

.default_profilesObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/zoom/profile_manager.rb', line 36

def self.default_profiles
    profiles = Hash.new

    @@ranking.each do |tool, clas|
        if (ScoobyDoo.where_are_you(tool))
            name = tool.gsub("-grep", "")
            obj = Zoom::Profile.profile_by_name(clas)
            profiles[name] = obj.new(name)
        end
    end

    Zoom::Profile.subclasses.each do |clas|
        case clas.to_s
        when /^Zoom::SecurityProfile.*/
            # Ignore these
        when /^Zoom::Profile::(Ag|Ack|Find|Grep|Pt|Rg)/
            # Ignore these
        else
            # Custom classes
            c = clas.new
            profiles[c.name] = c
        end
    end

    return profiles
end

.default_toolObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/zoom/profile_manager.rb', line 63

def self.default_tool
    if (@@tool && ScoobyDoo.where_are_you(@@tool))
        return @@tool
    end

    @@ranking.each do |tool, clas|
        return tool if (ScoobyDoo.where_are_you(tool))
    end

    return nil # shouldn't happen
end

.force_tool(tool = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/zoom/profile_manager.rb', line 75

def self.force_tool(tool = nil)
    if (tool == "ack")
        tool = "ack-grep" if (ScoobyDoo.where_are_you("ack-grep"))
    end

    tool = nil if (tool && !ScoobyDoo.where_are_you(tool))

    @@tool = tool
end

.security_profilesObject



85
86
87
88
89
90
91
# File 'lib/zoom/profile_manager.rb', line 85

def self.security_profiles
    profiles = Array.new
    Zoom::SecurityProfile.subclasses.each do |clas|
        profiles.push(clas.new)
    end
    return profiles
end