class Brakeman::FileTypeDetector
Constants
- MODEL_CLASSES
Public Class Methods
new()
click to toggle source
Calls superclass method
Brakeman::BaseProcessor::new
# File lib/brakeman/processors/lib/file_type_detector.rb, line 3 def initialize super(nil) reset end
Public Instance Methods
detect_type(file)
click to toggle source
# File lib/brakeman/processors/lib/file_type_detector.rb, line 8 def detect_type(file) reset process(file.ast) if @file_type.nil? @file_type = guess_from_path(file.path.relative) end @file_type || :libs end
guess_from_path(path)
click to toggle source
# File lib/brakeman/processors/lib/file_type_detector.rb, line 39 def guess_from_path path case when path.include?('app/models') :models when path.include?('app/controllers') :controllers when path.include?('config/initializers') :initializers when path.include?('lib/') :libs when path.match?(%r{config/environments/(?!production\.rb)$}) :skip when path.match?(%r{environments/production\.rb$}) :skip when path.match?(%r{application\.rb$}) :skip end end
process_class(exp)
click to toggle source
Calls superclass method
Brakeman::ProcessorHelper#process_class
# File lib/brakeman/processors/lib/file_type_detector.rb, line 24 def process_class exp name = class_name(exp.class_name) parent = class_name(exp.parent_name) if name.match(/Controller$/) @file_type = :controllers return exp elsif MODEL_CLASSES.include? parent @file_type = :models return exp end super end
Private Instance Methods
reset()
click to toggle source
# File lib/brakeman/processors/lib/file_type_detector.rb, line 60 def reset @file_type = nil end