Class: RipperTags::VimFormatter

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

Instance Attribute Summary

Attributes inherited from DefaultFormatter

#options

Instance Method Summary collapse

Methods inherited from DefaultFormatter

#check_supported_flags, #constant?, #extra_flag?, #field?, #initialize, #relative_path, #stdout?, #tag_file_dir

Constructor Details

This class inherits a constructor from RipperTags::DefaultFormatter

Instance Method Details

#display_class(tag) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/ripper-tags/vim_formatter.rb', line 51

def display_class(tag)
  if tag[:class]
    "\tclass:%s" % display_constant(tag[:class])
  else
    ""
  end
end

#display_constant(const) ⇒ Object



39
40
41
# File 'lib/ripper-tags/vim_formatter.rb', line 39

def display_constant(const)
  const.to_s.gsub('::', '.')
end

#display_excmd_info(tag) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/ripper-tags/vim_formatter.rb', line 43

def display_excmd_info(tag)
  if options.excmd == "number"
    "%d;\"" % tag.fetch(:line)
  else
    "/^%s$/;\"" % tag.fetch(:pattern).to_s.gsub('\\','\\\\\\\\').gsub('/','\\/')
  end
end

#display_inheritance(tag) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/ripper-tags/vim_formatter.rb', line 59

def display_inheritance(tag)
  if tag[:inherits] && 'class' == tag[:kind]
    "\tinherits:%s" % display_constant(tag[:inherits])
  else
    ""
  end
end

#display_kind(tag) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/ripper-tags/vim_formatter.rb', line 75

def display_kind(tag)
  case tag.fetch(:kind)
  when 'method' then 'f'
  when 'singleton method' then 'F'
  when 'constant' then 'C'
  when 'scope', 'belongs_to', 'has_one', 'has_many', 'has_and_belongs_to_many'
    'F'
  else tag[:kind].slice(0,1)
  end
end

#display_line_number(tag) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/ripper-tags/vim_formatter.rb', line 67

def display_line_number(tag)
  if field?('n') && tag[:line]
    "\tline:%s" % tag[:line]
  else
    ""
  end
end

#format(tag, name_field = :name) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ripper-tags/vim_formatter.rb', line 86

def format(tag, name_field = :name)
  "%s\t%s\t%s\t%s%s%s%s" % [
    tag.fetch(name_field),
    relative_path(tag),
    display_excmd_info(tag),
    display_kind(tag),
    display_line_number(tag),
    name_field == :full_name ? nil : display_class(tag),
    display_inheritance(tag),
  ]
end

#headerObject



13
14
15
16
17
18
# File 'lib/ripper-tags/vim_formatter.rb', line 13

def header
  "!_TAG_FILE_FORMAT\\t2\\t/extended format; --format=1 will not append ;\" to lines/\n!_TAG_FILE_SORTED\\t1\\t/0=unsorted, 1=sorted, 2=foldcase/\n  EOC\nend\n"

#include_qualified_names?Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/ripper-tags/vim_formatter.rb', line 8

def include_qualified_names?
  return @include_qualified_names if defined? @include_qualified_names
  @include_qualified_names = extra_flag?('q')
end

#supported_fieldsObject



6
# File 'lib/ripper-tags/vim_formatter.rb', line 6

def supported_fields() ['n'] end

#supported_flagsObject



5
# File 'lib/ripper-tags/vim_formatter.rb', line 5

def supported_flags() ['q'] end

#with_outputObject

prepend header and sort lines before closing output



21
22
23
24
25
26
27
28
29
30
# File 'lib/ripper-tags/vim_formatter.rb', line 21

def with_output
  super do |out|
    out.puts header
    @queued_write = []
    yield out
    @queued_write.sort.each do |line|
      out.puts(line)
    end
  end
end

#write(tag, out) ⇒ Object



32
33
34
35
36
37
# File 'lib/ripper-tags/vim_formatter.rb', line 32

def write(tag, out)
  @queued_write << format(tag)
  if include_qualified_names? && tag[:full_name] != tag[:name] && constant?(tag)
    @queued_write << format(tag, :full_name)
  end
end