Class: Henitai::MutationSkipDirectives::IndexBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/mutation_skip_directives.rb

Overview

Accumulates classified directives for one file, tracking open disable-start regions and raising on malformed directive usage.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ IndexBuilder

Returns a new instance of IndexBuilder.



123
124
125
126
127
128
129
130
# File 'lib/henitai/mutation_skip_directives.rb', line 123

def initialize(path)
  @path = path
  @trailing = {}
  @standalone = {}
  @regions = []
  @standalone_comment_lines = Set.new
  @open_region = nil
end

Instance Method Details

#indexObject



141
142
143
144
145
146
147
148
149
150
# File 'lib/henitai/mutation_skip_directives.rb', line 141

def index
  ensure_all_regions_closed!

  Index.new(
    trailing: @trailing.freeze,
    standalone: @standalone.freeze,
    regions: @regions.freeze,
    standalone_comment_lines: @standalone_comment_lines.freeze
  )
end

#record(comment, standalone:) ⇒ Object



132
133
134
135
136
137
138
139
# File 'lib/henitai/mutation_skip_directives.rb', line 132

def record(comment, standalone:)
  line = comment.location.start_line
  @standalone_comment_lines << line if standalone
  match = DIRECTIVE.match(comment.slice)
  return unless match

  dispatch(match, line, standalone)
end