Class: ColorTail::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/colortail/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ Configuration

Returns a new instance of Configuration.



4
5
6
7
8
9
10
11
# File 'lib/colortail/configuration.rb', line 4

def initialize(conf)
    @config_file = conf
    if File.exists?(conf)
        load @config_file
    else
        raise FileDoesNotExist, "Config file #{@config_file} cannot be found."
    end
end

Instance Method Details

#colorit(group) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/colortail/configuration.rb', line 13

def colorit(group)
    if Groupings.class == Hash
        Groupings["default"] = [] unless Groupings.has_key?('default')
        if Groupings.has_key?( group )
            return Groupings[group]
        else
            $stderr.puts "No such group '#{group}', falling back to default."
            return "'default' => []"
        end
    else
        raise ComplexRecord, "Config file syntax error"
    end
end

#display_match_groupsObject



36
37
38
39
40
# File 'lib/colortail/configuration.rb', line 36

def display_match_groups()
    Groupings.each_key do |group|
        puts "  * #{group}"
    end
end

#group_exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/colortail/configuration.rb', line 42

def group_exists?(key)
    Groupings.has_key?(key) ? true : false
end

#load_opts(group) ⇒ Object

Load everything from the config file here since the colorit() method isn’t available in the configuration object until after a new object has been instantiated.



30
31
32
33
34
# File 'lib/colortail/configuration.rb', line 30

def load_opts(group)
    colorset = Array.new
    colorset = self.colorit( group )
    return colorset
end