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
-
#file_list ⇒ Object
readonly
Returns the value of attribute file_list.
Instance Method Summary collapse
-
#initialize(tracker, app_tree) ⇒ FileParser
constructor
A new instance of FileParser.
- #parse_files(list, type) ⇒ Object
- #parse_ruby(input, path) ⇒ Object
- #read_files(list, type) ⇒ Object
- #read_path(path) ⇒ Object
Constructor Details
#initialize(tracker, app_tree) ⇒ FileParser
Returns a new instance of FileParser.
8 9 10 11 12 13 |
# File 'lib/brakeman/file_parser.rb', line 8 def initialize tracker, app_tree @tracker = tracker @timeout = @tracker.[:parser_timeout] @app_tree = app_tree @file_list = {} end |
Instance Attribute Details
#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
#parse_files(list, type) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/brakeman/file_parser.rb', line 15 def parse_files list, type read_files list, type do |path, contents| if ast = parse_ruby(contents, path) ASTFile.new(path, ast) end end end |
#parse_ruby(input, path) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/brakeman/file_parser.rb', line 34 def parse_ruby input, path begin Brakeman.debug "Parsing #{path}" RubyParser.new.parse input, path, @timeout rescue Racc::ParseError => e @tracker.error e, "Could not parse #{path}" nil rescue Timeout::Error => e @tracker.error Exception.new("Parsing #{path} took too long (> #{@timeout} seconds). Try increasing the limit with --parser-timeout"), caller nil rescue => e @tracker.error e.exception(e. + "\nWhile processing #{path}"), e.backtrace nil end end |
#read_files(list, type) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/brakeman/file_parser.rb', line 23 def read_files list, type @file_list[type] ||= [] list.each do |path| result = yield path, read_path(path) if result @file_list[type] << result end end end |
#read_path(path) ⇒ Object
50 51 52 |
# File 'lib/brakeman/file_parser.rb', line 50 def read_path path @app_tree.read_path path end |