Class: RipperTags::VimAppendFormatter
- Inherits:
-
Object
- Object
- RipperTags::VimAppendFormatter
- Defined in:
- lib/ripper-tags/vim_append_formatter.rb
Instance Method Summary collapse
-
#initialize(fmt) ⇒ VimAppendFormatter
constructor
Wraps a VimFormatter.
- #with_output ⇒ Object
- #write(tag, out) ⇒ Object
Constructor Details
#initialize(fmt) ⇒ VimAppendFormatter
Wraps a VimFormatter
6 7 8 9 |
# File 'lib/ripper-tags/vim_append_formatter.rb', line 6 def initialize(fmt) raise 'append is only possible to a file' if fmt.stdout? @formatter = fmt end |
Instance Method Details
#with_output ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ripper-tags/vim_append_formatter.rb', line 11 def with_output orig_lines = begin File.readlines(@formatter..tag_file_name) rescue Errno::ENOENT [] end @seen_filenames = Set.new @formatter.with_output do |out| yield out orig_lines.each do |line| f1, f2, = line.split("\t", 3) # skip repeating header entries next if f1 == '!_TAG_FILE_FORMAT' || f1 == '!_TAG_FILE_SORTED' # skip old tags for newly processed files next if f1.index('!_TAG_') != 0 && @seen_filenames.include?(f2) # preserve other tags from original file @formatter.write_line(line) end end end |
#write(tag, out) ⇒ Object
34 35 36 37 |
# File 'lib/ripper-tags/vim_append_formatter.rb', line 34 def write(tag, out) @formatter.write(tag, out) @seen_filenames << @formatter.relative_path(tag) end |