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(source: []) ⇒ Scanner

Returns a new instance of Scanner.



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

def initialize(source: [])
  @source      = source
  @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

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
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 rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity



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

def scan
  source.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)
    line_detection    = nil if context && module_definition?(line, line_detection)
    line_detection    = nil if commented?(line, line_detection)
    context_detection = AxR.app.layer_names.detect { |layer| module_definition?(line, layer) }

    next unless context_detection || line_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 && line_detection
  end

  self
end