class ApacheCrunch::Filter

DSL routine(s) that filter(s) for entries for which the given block evaluates to true

This can be called as ‘filter()’, which means the filtering happens in a temporary file, or as ‘filter(path)’, which means the filtering happens in the given file. It can also be called as ‘filter!()’, which means the filtering happens in place, clobbering what’s in apachecrunch’s target file.

Public Instance Methods

_make_results_file(path, in_place) click to toggle source

Returns a writable file object to which the results of the filter should be written.

# File lib/procedure_dsl.rb, line 100
def _make_results_file(path, in_place)
    if path.nil?
        # If no path passed (this includes the case where the filter is being performed
        # in place), we want a temp file.
        return Tempfile.new("apachecrunch")
    else
        return open(path, "w")
    end
end
execute(path=nil, in_place=false, &blk) click to toggle source
# File lib/procedure_dsl.rb, line 78
def execute(path=nil, in_place=false, &blk)
    @_in_place = in_place
    @_results_file = _make_results_file(path, in_place)

    while @_current_entry = @_log_parser.next_entry
        if instance_eval(&blk)
            @_results_file.write(@_current_entry.fetch(:text))
        end
    end
end
finish() click to toggle source
# File lib/procedure_dsl.rb, line 89
def finish
    @_results_file.close
    @_results_file = open(@_results_file.path)
    if @_in_place
        @_log_parser.replace_file!(@_results_file)
    else
        @_log_parser.set_file!(@_results_file)
    end
end