class AxR::Scanner
Constants
- COMMENT
- MODULE
- SPACE
Attributes
context[R]
dependecies[R]
source[R]
warnings[R]
Public Class Methods
new(source: [])
click to toggle source
# File lib/axr/scanner.rb, line 10 def initialize(source: []) @source = source @dependecies = [] @warnings = [] @context = nil end
Public Instance Methods
scan()
click to toggle source
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
# 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
Private Instance Methods
check_space_before(line, line_detection)
click to toggle source
# File lib/axr/scanner.rb, line 70 def check_space_before(line, line_detection) return unless line_detection line_detection if line[line.index(line_detection) - 1] == SPACE end
cleanup_loc(loc)
click to toggle source
# File lib/axr/scanner.rb, line 64 def cleanup_loc(loc) loc.chomp.strip end
commented?(line, layer)
click to toggle source
# File lib/axr/scanner.rb, line 84 def commented?(line, layer) return false if line.empty? || layer.nil? line.split(layer).first&.include?(COMMENT) end
detect_context(value, loc, loc_num)
click to toggle source
rubocop:enable Metrics/AbcSize rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity
# File lib/axr/scanner.rb, line 45 def detect_context(value, loc, loc_num) @context = Detection.new(name: value, loc: cleanup_loc(loc), loc_num: loc_num) end
detect_dependency(value, loc, loc_num)
click to toggle source
# File lib/axr/scanner.rb, line 49 def detect_dependency(value, loc, loc_num) return if context && value == context.name @dependecies << Detection.new(name: value, loc: cleanup_loc(loc), loc_num: loc_num) end
detect_warning(value, loc, loc_num)
click to toggle source
# File lib/axr/scanner.rb, line 55 def detect_warning(value, loc, loc_num) return if value == context.name return if AxR.app.legal?(context.name, value) msg = "#{context.name} layer should not be familiar with #{value}" @warnings << Warning.new(message: msg, loc: cleanup_loc(loc), loc_num: loc_num) end
module_definition?(line, layer)
click to toggle source
# File lib/axr/scanner.rb, line 78 def module_definition?(line, layer) line.include?("#{MODULE} #{layer}") end