Class: Zoom::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(file = nil) ⇒ Config

Returns a new instance of Config.



104
105
106
107
# File 'lib/zoom/config.rb', line 104

def initialize(file = nil)
    file ||= "~/.zoomrc"
    super(file)
end

Instance Method Details

#current_profile_name(name = nil) ⇒ Object



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

def current_profile_name(name = nil)
    set("current_profile_name", name) if (name)
    return get("current_profile_name")
end

#default_config ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/zoom/config.rb', line 43

def default_config
    default = Zoom::ProfileManager.default_profile
    profiles = Zoom::ProfileManager.default_profiles

    clear
    set("color", true)
    set("color_filename", "green")
    set("color_lineno", "white")
    set("color_match", "black.on_white")
    set("color_tag", "red")
    set("current_profile_name", default)
    set("editor", "")
    set("profiles", profiles)
end

#editor(ed = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/zoom/config.rb', line 58

def editor(ed = nil)
    if (ed)
        e = ScoobyDoo.where_are_you(ed)
        raise Zoom::Error::ExecutableNotFound.new(ed) if (e.nil?)
        set("editor", ed)
    end

    e = get("editor")
    e = ENV["EDITOR"] if (e.nil? || e.empty?)
    e = "vim" if (e.nil? || e.empty?)
    e = ScoobyDoo.where_are_you(e)
    e = ScoobyDoo.where_are_you("vi") if (e.nil?)
    raise Zoom::Error::ExecutableNotFound.new("vi") if (e.nil?)

    return e
end

#get_profile(name) ⇒ Object



109
110
111
# File 'lib/zoom/config.rb', line 109

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

#get_profile_names ⇒ Object



113
114
115
116
117
# File 'lib/zoom/config.rb', line 113

def get_profile_names
    return get("profiles").keys.sort do |a, b|
        a.downcase <=> b.downcase
    end
end

#get_profiles(display_error = true) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/zoom/config.rb', line 119

def get_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

#has_profile?(name) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/zoom/config.rb', line 75

def has_profile?(name)
    return get("profiles").has_key?(name)
end

#hilight(flag = nil) ⇒ Object



79
80
81
82
# File 'lib/zoom/config.rb', line 79

def hilight(flag = nil)
    set("color", flag) if (!flag.nil?)
    return get("color")
end

#hilight_filename(str) ⇒ Object



84
85
86
87
# File 'lib/zoom/config.rb', line 84

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

#hilight_lineno(str) ⇒ Object



89
90
91
92
# File 'lib/zoom/config.rb', line 89

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

#hilight_match(str) ⇒ Object



94
95
96
97
# File 'lib/zoom/config.rb', line 94

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

#hilight_tag(str) ⇒ Object



99
100
101
102
# File 'lib/zoom/config.rb', line 99

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

#set_profiles(profiles) ⇒ Object



131
132
133
# File 'lib/zoom/config.rb', line 131

def set_profiles(profiles)
    set("profiles", profiles)
end

#validate_colors ⇒ Object



149
150
151
152
153
154
155
# File 'lib/zoom/config.rb', line 149

def validate_colors
    # Validate colors
    color_filename
    color_lineno
    color_match
    color_tag
end