Class: Ruby::Merge::BlockDirectiveDetector
- Inherits:
-
Object
- Object
- Ruby::Merge::BlockDirectiveDetector
- Defined in:
- lib/ruby/merge/block_directive_detector.rb
Overview
Detects Ruby comment block directive pairs in source lines.
This is Ruby-specific substrate behavior shared by Ruby parser providers. Parser-specific gems may consume the spans and project them into their own node types, but directive token semantics should live here. Directive scanning intentionally keeps the paired-stack validation in one class so every caller receives identical malformed-input diagnostics. rubocop:disable Metrics/AbcSize, Metrics/BlockLength, Metrics/ClassLength rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
Defined Under Namespace
Classes: Span
Constant Summary collapse
- NOCOV_TOKEN =
':nocov:'- SIMPLECOV_DISABLE_RE =
/\A\s*#\s*simplecov\s*:\s*disable\b/i- SIMPLECOV_ENABLE_RE =
/\A\s*#\s*simplecov\s*:\s*enable\b/i- DIRECTIVE_CONTENT_RE =
/\A(?::nocov:|[\w-]+:(?:freeze|unfreeze))\z/i
Class Method Summary collapse
- .coverage_directive_line?(line, nocov_token: NOCOV_TOKEN) ⇒ Boolean
- .directive_content?(content) ⇒ Boolean
- .nocov_re(nocov_token = NOCOV_TOKEN) ⇒ Object
- .simplecov_disable_re ⇒ Object
- .simplecov_enable_re ⇒ Object
Instance Method Summary collapse
- #detect_spans ⇒ Object
-
#initialize(lines, freeze_token: nil, nocov_token: NOCOV_TOKEN, source_label: nil) ⇒ BlockDirectiveDetector
constructor
A new instance of BlockDirectiveDetector.
Constructor Details
#initialize(lines, freeze_token: nil, nocov_token: NOCOV_TOKEN, source_label: nil) ⇒ BlockDirectiveDetector
Returns a new instance of BlockDirectiveDetector.
48 49 50 51 52 53 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 48 def initialize(lines, freeze_token: nil, nocov_token: NOCOV_TOKEN, source_label: nil) @lines = lines @freeze_token = freeze_token @nocov_token = nocov_token @source_label = source_label end |
Class Method Details
.coverage_directive_line?(line, nocov_token: NOCOV_TOKEN) ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 23 def coverage_directive_line?(line, nocov_token: NOCOV_TOKEN) stripped = line.to_s.chomp stripped.match?(simplecov_disable_re) || stripped.match?(simplecov_enable_re) || stripped.match?(nocov_re(nocov_token)) end |
.directive_content?(content) ⇒ Boolean
30 31 32 33 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 30 def directive_content?(content) DIRECTIVE_CONTENT_RE.match?(content.to_s.strip) || coverage_directive_line?("# #{content}") end |
.nocov_re(nocov_token = NOCOV_TOKEN) ⇒ Object
43 44 45 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 43 def nocov_re(nocov_token = NOCOV_TOKEN) /\A\s*#\s?#{Regexp.escape(nocov_token)}\s*\z/i end |
.simplecov_disable_re ⇒ Object
35 36 37 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 35 def simplecov_disable_re SIMPLECOV_DISABLE_RE end |
.simplecov_enable_re ⇒ Object
39 40 41 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 39 def simplecov_enable_re SIMPLECOV_ENABLE_RE end |
Instance Method Details
#detect_spans ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 55 def detect_spans raw_spans = [] raw_spans.concat(detect_freeze_spans) if @freeze_token raw_spans.concat(detect_nocov_spans) validate_no_crossing(raw_spans.sort_by(&:start_line)) end |