Class: Brakeman::FileParser
- Inherits:
-
Object
- Object
- Brakeman::FileParser
- Defined in:
- lib/brakeman/file_parser.rb
Overview
This class handles reading and parsing files.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#file_list ⇒ Object
readonly
Returns the value of attribute file_list.
Instance Method Summary collapse
- #error(exception) ⇒ Object
-
#initialize(app_tree, timeout) ⇒ FileParser
constructor
A new instance of FileParser.
- #parse_files(list) ⇒ Object
-
#parse_ruby(input, path) ⇒ Object
path can be a string or a Brakeman::FilePath.
- #read_files(list) ⇒ Object
Constructor Details
#initialize(app_tree, timeout) ⇒ FileParser
Returns a new instance of FileParser.
8 9 10 11 12 13 |
# File 'lib/brakeman/file_parser.rb', line 8 def initialize app_tree, timeout @app_tree = app_tree @timeout = timeout @file_list = [] @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/brakeman/file_parser.rb', line 6 def errors @errors end |
#file_list ⇒ Object (readonly)
Returns the value of attribute file_list.
6 7 8 |
# File 'lib/brakeman/file_parser.rb', line 6 def file_list @file_list end |
Instance Method Details
#error(exception) ⇒ Object
53 54 55 56 |
# File 'lib/brakeman/file_parser.rb', line 53 def error exception @errors << exception nil end |
#parse_files(list) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/brakeman/file_parser.rb', line 15 def parse_files list read_files list do |path, contents| if ast = parse_ruby(contents, path.relative) ASTFile.new(path, ast) end end end |
#parse_ruby(input, path) ⇒ Object
path can be a string or a Brakeman::FilePath
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/brakeman/file_parser.rb', line 36 def parse_ruby input, path if path.is_a? Brakeman::FilePath path = path.relative end begin Brakeman.debug "Parsing #{path}" RubyParser.new.parse input, path, @timeout rescue Racc::ParseError => e error e.exception(e. + "\nCould not parse #{path}") rescue Timeout::Error => e error Exception.new("Parsing #{path} took too long (> #{@timeout} seconds). Try increasing the limit with --parser-timeout") rescue => e error e.exception(e. + "\nWhile processing #{path}") end end |
#read_files(list) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/brakeman/file_parser.rb', line 23 def read_files list list.each do |path| file = @app_tree.file_path(path) result = yield file, file.read if result @file_list << result end end end |