Class: AxR::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/axr/scanner.rb,
lib/axr/scanner/warning.rb,
lib/axr/scanner/detection.rb

Defined Under Namespace

Classes: Detection, Warning

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path:) ⇒ Scanner

Returns a new instance of Scanner.



10
11
12
13
14
15
# File 'lib/axr/scanner.rb', line 10

def initialize(file_path:)
  @file_path   = file_path
  @dependecies = []
  @warnings    = []
  @context     = nil
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



8
9
10
# File 'lib/axr/scanner.rb', line 8

def context
  @context
end

#dependeciesObject (readonly)

Returns the value of attribute dependecies.



8
9
10
# File 'lib/axr/scanner.rb', line 8

def dependecies
  @dependecies
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



8
9
10
# File 'lib/axr/scanner.rb', line 8

def file_path
  @file_path
end

#warningsObject (readonly)

Returns the value of attribute warnings.



8
9
10
# File 'lib/axr/scanner.rb', line 8

def warnings
  @warnings
end

Instance Method Details

#scanObject

rubocop:disable Metrics/AbcSize



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/axr/scanner.rb', line 18

def scan
  File.open(file_path).each.with_index do |line, index|
    loc_num = index + 1

    line_detection    = AxR.app.layer_names.detect { |layer| line.include?(layer) }
    line_detection    = check_space_before(line, line_detection)
    context_detection = AxR.app.layer_names.detect { |layer| line.include?("module #{layer}") }

    next unless line_detection || context_detection

    detect_context(context_detection, line, loc_num) if context_detection && !context
    detect_dependency(line_detection, line, loc_num)
    detect_warning(line_detection,    line, loc_num) if context
  end

  self
end