Module: Arachni::Component::Utilities

Extended by:
Utilities
Includes:
Utilities
Included in:
Base, Base, Utilities
Defined in:
lib/arachni/component/utilities.rb

Overview

Includes some useful methods for the components.

Author:

Instance Method Summary collapse

Methods included from Utilities

#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #cookie_decode, #cookie_encode, #cookies_from_file, #cookies_from_parser, #cookies_from_response, #exception_jail, #exclude_path?, #follow_protocol?, #form_decode, #form_encode, #forms_from_parser, #forms_from_response, #full_and_absolute_url?, #generate_token, #get_path, #hms_to_seconds, #html_decode, #html_encode, #include_path?, #links_from_parser, #links_from_response, #normalize_url, #page_from_response, #page_from_url, #parse_set_cookie, #path_in_domain?, #path_too_deep?, #port_available?, #rand_port, #random_seed, #redundant_path?, #regexp_array_match, #remove_constants, #request_parse_body, #seconds_to_hms, #skip_page?, #skip_path?, #skip_resource?, #skip_response?, #to_absolute, #uri_decode, #uri_encode, #uri_parse, #uri_parse_query, #uri_parser, #uri_rewrite

Instance Method Details

#read_file(filename, &block) ⇒ Object

Parameters:

  • filename (String)

    Filename, without the path.

  • block (Block)

    The block to be passed each line as it's read.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/arachni/component/utilities.rb', line 22

def read_file( filename, &block )
    component_path = block_given? ?
        block.source_location.first : caller_path(1)

    # The name of the component that called us.
    component_name = File.basename( component_path, '.rb' )

    # The path to the component's data file directory.
    path  = File.expand_path( File.dirname( component_path ) ) +
        "/#{component_name}/"

    File.open( "#{path}/#{filename}" ) do |file|
        if block_given?
            # I really hope that ruby frees each line as soon as possible
            # otherwise this provides no advantage
            file.each { |line| yield line.strip }
        else
            file.read.lines.map { |l| l.strip }
        end
    end
end