Sha256: 560d85f10c40f6b5b8fed0b7943a16e46bdc9fa1d684b279058dc0b5a2a581ee

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

=begin
    Copyright 2010-2014 Tasos Laskos <tasos.laskos@arachni-scanner.com>

    This file is part of the Arachni Framework project and is subject to
    redistribution and commercial restrictions. Please see the Arachni Framework
    web site for more information on licensing and terms of use.
=end

module Arachni
module Component

# Includes some useful methods for the components.
#
# @author Tasos "Zapotek" Laskos <tasos.laskos@arachni-scanner.com>
module Utilities
    include Arachni::Utilities

    # @param    [String]    filename
    #   Filename, without the path.
    # @param    [Block]     block
    #   The block to be passed each line as it's read.
    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

    extend self

end

end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
arachni-1.0.6 lib/arachni/component/utilities.rb
arachni-1.0.5 lib/arachni/component/utilities.rb
arachni-1.0.4 lib/arachni/component/utilities.rb
arachni-1.0.3 lib/arachni/component/utilities.rb
arachni-1.0.2 lib/arachni/component/utilities.rb
arachni-1.0.1 lib/arachni/component/utilities.rb
arachni-1.0 lib/arachni/component/utilities.rb