class ApacheCrunch::FormatDefinitionFinder

Finds a named log format string in the configuration file(s)

Public Class Methods

new(file_cls=File, env=ENV) click to toggle source

Initializes the FormatStringFinder.

# File lib/config.rb, line 11
def initialize(file_cls=File, env=ENV)
    @_file_cls=file_cls
    @_env=env
end

Public Instance Methods

_search_path() click to toggle source
# File lib/config.rb, line 38
def _search_path
    [".", "./etc",
     @_file_cls.join(@_env["HOME"], ".apachecrunch"),
     "/etc/apachecrunch"]
end
find(format_name) click to toggle source

Finds the given format string in the configuration file(s)

If none exists, returns nil.

# File lib/config.rb, line 19
def find(format_name)
    name_as_symbol = format_name.to_sym

    formats = @@DEFAULT_FORMATS.clone
    _search_path.each do |dir|
        config_path = @_file_cls.join(dir, @@FILE_NAME)
        if @_file_cls.readable?(config_path)
            config_file = @_file_cls.open(@_file_cls.join(dir, @@FILE_NAME))
            eval config_file.read
        end

        if formats.key?(format_name.to_sym)
            return formats[format_name.to_sym].gsub(/\\"/, '"')
        end
    end

    raise "Failed to find the format '#{format_name}' in the search path: #{_search_path.inspect}"
end