Class: LintFu::Plugins::Rails::IssueBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs_root) ⇒ IssueBuilder

Returns a new instance of IssueBuilder.



6
7
8
# File 'lib/lint_fu/plugins/rails/issue_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/plugins/rails/issue_builder.rb', line 4

def fs_root
  @fs_root
end

Instance Method Details

#build(context, scan) ⇒ 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
# File 'lib/lint_fu/plugins/rails/issue_builder.rb', line 10

def build(context, scan)
  models_dir      = File.join(scan.fs_root, 'app', 'models')
  controllers_dir = File.join(scan.fs_root, 'app', 'controllers')
  views_dir       = File.join(scan.fs_root, 'app', 'views')

  #Scan controllers
  Dir.glob(File.join(controllers_dir, '**', '*.rb')).each do |filename|
    sexp = LintFu::Parser.parse_ruby(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|
    sexp = LintFu::Parser.parse_ruby(filename)
    visitor = LintFu::Visitor.new
    visitor.observers << SqlInjectionChecker.new(scan, context, filename, 0.2)
    visitor.observers << UnsafeFindChecker.new(scan, context, filename)
    visitor.process(sexp)          
  end
end