Class: LintFu::Rails::ScanBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lint_fu/rails/scan_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs_root) ⇒ ScanBuilder

Returns a new instance of ScanBuilder.



6
7
8
# File 'lib/lint_fu/rails/scan_builder.rb', line 6

def initialize(fs_root)
  @fs_root = fs_root
end

Instance Attribute Details

#fs_rootObject (readonly)

Returns the value of attribute fs_root.



4
5
6
# File 'lib/lint_fu/rails/scan_builder.rb', line 4

def fs_root
  @fs_root
end

Instance Method Details

#scan(context) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lint_fu/rails/scan_builder.rb', line 10

def scan(context)
  scan    = LintFu::Scan.new(@fs_root)

  models_dir      = File.join(@fs_root, 'app', 'models')
  controllers_dir = File.join(@fs_root, 'app', 'controllers')
  views_dir       = File.join(@fs_root, 'app', 'views')

  #Scan controllers
  Dir.glob(File.join(controllers_dir, '**', '*.rb')).each do |filename|
    contents = File.read(filename)
    parser = RubyParser.new
    sexp = parser.parse(contents, filename)
    visitor = LintFu::Visitor.new
    visitor.observers << BuggyEagerLoadChecker.new(scan, context, filename)
    visitor.observers << SqlInjectionChecker.new(scan, context, filename)
    visitor.observers << UnsafeFindChecker.new(scan, context, filename)
    visitor.process(sexp)
  end

  #Scan models
  Dir.glob(File.join(models_dir, '**', '*.rb')).each do |filename|
    contents = File.read(filename)
    parser = RubyParser.new
    sexp = parser.parse(contents, filename)
    visitor = LintFu::Visitor.new
    visitor.observers << SqlInjectionChecker.new(scan, context, filename, 0.2)
    visitor.process(sexp)          
  end

  return scan
end