Class: Zoom::Config

Inherits:
JSONConfig
  • Object
show all
Extended by:
JSONConfig::Keys
Defined in:
lib/zoom/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Config

Returns a new instance of Config.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/zoom/config.rb', line 49

def initialize(file = nil)
    file ||= "~/.config/zoom/rc"
    defaultprof = Zoom::ProfileManager.default_tool
    profiles = Zoom::ProfileManager.default_profiles
    @defaults = {
        "color_filename" => "green",
        "color_lineno" => "white",
        "color_match" => "black.on_white",
        "color_tag" => "red",
        "current_profile_name" => defaultprof,
        "editor" => nil,
        "hilight" => true,
        "profiles" => profiles
    }
    super(file)
end

Instance Method Details

#add_security_profilesObject



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

def add_security_profiles
    profiles = parse_profiles
    Zoom::ProfileManager::security_profiles.each do |profile|
        profiles[profile.name] = profile
    end
    set_profiles(profiles)
end

#get_profile(name) ⇒ Object



66
67
68
# File 'lib/zoom/config.rb', line 66

def get_profile(name)
    return parse_profiles(false)[name]
end

#get_profile_namesObject



70
71
72
73
74
# File 'lib/zoom/config.rb', line 70

def get_profile_names
    return get_profiles.keys.sort do |a, b|
        a.downcase <=> b.downcase
    end
end

#has_profile?(name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/zoom/config.rb', line 25

def has_profile?(name)
    return profiles? && get_profiles.has_key?(name)
end

#hilight_filename(str) ⇒ Object



29
30
31
32
# File 'lib/zoom/config.rb', line 29

def hilight_filename(str)
    return str if (!hilight?)
    get_color_filename.split(".").inject(str, :send)
end

#hilight_lineno(str) ⇒ Object



34
35
36
37
# File 'lib/zoom/config.rb', line 34

def hilight_lineno(str)
    return str if (!hilight?)
    get_color_lineno.split(".").inject(str, :send)
end

#hilight_match(str) ⇒ Object



39
40
41
42
# File 'lib/zoom/config.rb', line 39

def hilight_match(str)
    return str if (!hilight?)
    get_color_match.split(".").inject(str, :send)
end

#hilight_tag(str) ⇒ Object



44
45
46
47
# File 'lib/zoom/config.rb', line 44

def hilight_tag(str)
    return str if (!hilight?)
    get_color_tag.split(".").inject(str, :send)
end

#parse_profiles(display_error = true) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/zoom/config.rb', line 76

def parse_profiles(display_error = true)
    profiles = Hash.new
    get_profiles.each do |name, prof|
        begin
            profiles[name] = Zoom::Profile.from_json(prof)
        rescue Zoom::Error => e
            puts(e.message) if (display_error)
        end
    end
    return profiles
end

#use_editor(editor) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/zoom/config.rb', line 88

def use_editor(editor)
    if (editor && !editor.empty?)
        ed, _, _ = editor.partition(" ")
        if (ScoobyDoo.where_are_you(ed).nil?)
            raise Zoom::Error::ExecutableNotFound.new(ed)
        end
    end
    set_editor(editor)
end

#validate_colorsObject



107
108
109
110
111
112
113
# File 'lib/zoom/config.rb', line 107

def validate_colors
    # Validate colors
    validate_color(get_color_filename)
    validate_color(get_color_lineno)
    validate_color(get_color_match)
    validate_color(get_color_tag)
end