class Zoom::Config

Public Class Methods

new(file = nil) click to toggle source
Calls superclass method
# 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

Public Instance Methods

add_security_profiles() click to toggle source
# 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) click to toggle source
# File lib/zoom/config.rb, line 66
def get_profile(name)
    return parse_profiles(false)[name]
end
get_profile_names() click to toggle source
# 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) click to toggle source
# File lib/zoom/config.rb, line 25
def has_profile?(name)
    return profiles? && get_profiles.has_key?(name)
end
hilight_filename(str) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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_colors() click to toggle source
# 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

Private Instance Methods

validate_color(clr) click to toggle source
# File lib/zoom/config.rb, line 98
def validate_color(clr)
    @valid ||= String.colors.keys.concat(String.modes.keys)
    clr.split(".").each do |c|
        next if (@valid.include?(c.gsub(/^on_/, "")))
        raise Zoom::Error::InvalidColor.new(clr)
    end
end