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

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

Constructor Details

This class inherits a constructor from RipperTags::DefaultFormatter

Instance Method Details

#display_class(tag) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/ripper-tags/vim_formatter.rb', line 46

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

#display_constant(const) ⇒ Object



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

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

#display_inheritance(tag) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/ripper-tags/vim_formatter.rb', line 54

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

#display_kind(tag) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/ripper-tags/vim_formatter.rb', line 62

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_pattern(tag) ⇒ Object



42
43
44
# File 'lib/ripper-tags/vim_formatter.rb', line 42

def display_pattern(tag)
  tag.fetch(:pattern).to_s.gsub('\\','\\\\\\\\').gsub('/','\\/')
end

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



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

def format(tag, name_field = :name)
  "%s\t%s\t/^%s$/;\"\t%s%s%s" % [
    tag.fetch(name_field),
    relative_path(tag),
    display_pattern(tag),
    display_kind(tag),
    name_field == :full_name ? nil : display_class(tag),
    display_inheritance(tag),
  ]
end

#headerObject



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

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

#include_qualified_names?Boolean

Returns:

  • (Boolean)


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

def include_qualified_names?
  return @include_qualified_names if defined? @include_qualified_names
  @include_qualified_names = extra_flag?('q')
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



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

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



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

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