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.
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.
44 45 46 47 48 49 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 44 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
19 20 21 22 23 24 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 19 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
26 27 28 29 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 26 def directive_content?(content) DIRECTIVE_CONTENT_RE.match?(content.to_s.strip) || coverage_directive_line?("# #{content}") end |
.nocov_re(nocov_token = NOCOV_TOKEN) ⇒ Object
39 40 41 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 39 def nocov_re(nocov_token = NOCOV_TOKEN) /\A\s*#\s?#{Regexp.escape(nocov_token)}\s*\z/i end |
.simplecov_disable_re ⇒ Object
31 32 33 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 31 def simplecov_disable_re SIMPLECOV_DISABLE_RE end |
.simplecov_enable_re ⇒ Object
35 36 37 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 35 def simplecov_enable_re SIMPLECOV_ENABLE_RE end |
Instance Method Details
#detect_spans ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/ruby/merge/block_directive_detector.rb', line 51 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 |