Class: RipperTags::EmacsAppendFormatter
- Inherits:
-
Object
- Object
- RipperTags::EmacsAppendFormatter
- Defined in:
- lib/ripper-tags/emacs_append_formatter.rb
Instance Method Summary collapse
-
#initialize(fmt) ⇒ EmacsAppendFormatter
constructor
Wraps an EmacsFormatter.
- #parse_tag_file ⇒ Object
- #with_output ⇒ Object
- #write(tag, out) ⇒ Object
Constructor Details
#initialize(fmt) ⇒ EmacsAppendFormatter
Wraps an EmacsFormatter
6 7 8 9 |
# File 'lib/ripper-tags/emacs_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
#parse_tag_file ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ripper-tags/emacs_append_formatter.rb', line 31 def parse_tag_file section_map = {} File.open(@formatter..tag_file_name) do |old_file| while line = old_file.read(2) raise 'expected "\f\n", got %p' % line unless "\x0C\n" == line filename, length = old_file.gets.chomp.split(',') section_map[filename] = old_file.read(length.to_i) end end section_map rescue Errno::ENOENT {} end |
#with_output ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ripper-tags/emacs_append_formatter.rb', line 11 def with_output old_sections = parse_tag_file @seen_filenames = Set.new @formatter.with_output do |out| yield out @formatter.flush_file_section(out) old_sections.each do |filename, data| next if @seen_filenames.include?(filename) @formatter.write_section(filename, data, out) end end end |
#write(tag, out) ⇒ Object
26 27 28 29 |
# File 'lib/ripper-tags/emacs_append_formatter.rb', line 26 def write(tag, out) @formatter.write(tag, out) @seen_filenames << @formatter.relative_path(tag) end |