module Arachni::Component::Utilities
Includes some useful methods for the components.
@author Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>
Public Instance Methods
read_file( filename ) { |strip| ... }
click to toggle source
@param [String] filename
Filename, without the path.
@param [Block] block
The block to be passed each line as it's read.
# 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