Class: Bulletproof::Detectors::ExcessiveIncludesDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/bulletproof/detectors/excessive_includes_detector.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ExcessiveIncludesDetector

Returns a new instance of ExcessiveIncludesDetector.



29
30
31
# File 'lib/bulletproof/detectors/excessive_includes_detector.rb', line 29

def initialize(config)
  @config = config
end

Instance Method Details

#call(source, file: "(string)") ⇒ Array<Violation>

Parameters:

  • source (String)

    Rubyソースコード

  • file (String) (defaults to: "(string)")

    ファイルパス(表示用)

Returns:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bulletproof/detectors/excessive_includes_detector.rb', line 36

def call(source, file: "(string)")
  processed = RuboCop::AST::ProcessedSource.new(source, RUBY_VERSION.to_f, file)
  return [] unless processed.valid_syntax?

  parent_map = build_parent_map(processed.ast)
  violations = []
  collect_includes_nodes(processed.ast).each do |node|
    check(node, violations, file, parent_map)
  end
  violations
end