Class: RipperTags::JSONFormatter

Inherits:
DefaultFormatter show all
Defined in:
lib/ripper-tags/json_formatter.rb

Instance Attribute Summary

Attributes inherited from DefaultFormatter

#options

Instance Method Summary collapse

Methods inherited from DefaultFormatter

#check_supported_flags, #constant?, #display_inheritance, #display_kind, #extra_flag?, #field?, #format, #initialize, #relative_path, #stdout?, #supported_fields, #tag_file_dir

Constructor Details

This class inherits a constructor from RipperTags::DefaultFormatter

Instance Method Details

#stream_format?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/ripper-tags/json_formatter.rb', line 12

def stream_format?
  return @stream_format if defined? @stream_format
  @stream_format = extra_flag?('s')
end

#supported_flagsObject



10
# File 'lib/ripper-tags/json_formatter.rb', line 10

def supported_flags() ['s'] end

#with_outputObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ripper-tags/json_formatter.rb', line 17

def with_output
  super do |true_out|
    buffer = []
    yield buffer

    if stream_format?
      buffer.each { |tag| true_out.puts ::JSON.dump(tag) }
    else
      true_out.write ::JSON.dump(buffer)
    end
  end
end

#write(tag, buffer) ⇒ Object



30
31
32
# File 'lib/ripper-tags/json_formatter.rb', line 30

def write(tag, buffer)
  buffer << tag
end