Class: RipperTags::VimFormatter
Instance Attribute Summary
#options
Instance Method Summary
collapse
#check_supported_flags, #constant?, #extra_flag?, #field?, #initialize, #relative_path, #stdout?, #tag_file_dir
Instance Method Details
#display_class(tag) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/ripper-tags/vim_formatter.rb', line 63
def display_class(tag)
if tag[:class]
"\tclass:%s" % display_constant(tag[:class])
else
""
end
end
|
#display_constant(const) ⇒ Object
43
44
45
|
# File 'lib/ripper-tags/vim_formatter.rb', line 43
def display_constant(const)
const.to_s.gsub('::', '.')
end
|
#display_excmd_info(tag) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/ripper-tags/vim_formatter.rb', line 47
def display_excmd_info(tag)
case options.excmd
when 'n', 'number'
"%d;\"" % tag.fetch(:line)
when nil, 'p', 'pattern', 'm', 'mixed'
"/^%s$/;\"" % tag.fetch(:pattern).to_s.gsub('\\','\\\\\\\\').gsub('/','\\/')
when 'c', 'combined'
"%d;/^%s$/;\"" % [
tag.fetch(:line) - 1,
tag.fetch(:pattern).to_s.gsub('\\','\\\\\\\\').gsub('/','\\/')
]
else
raise 'invalid excmd value: %p', options.excmd
end
end
|
#display_inheritance(tag) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/ripper-tags/vim_formatter.rb', line 71
def display_inheritance(tag)
if tag[:inherits] && 'class' == tag[:kind]
"\tinherits:%s" % display_constant(tag[:inherits])
else
""
end
end
|
#display_kind(tag) ⇒ Object
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/ripper-tags/vim_formatter.rb', line 91
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_language ⇒ Object
87
88
89
|
# File 'lib/ripper-tags/vim_formatter.rb', line 87
def display_language
"\tlanguage:Ruby" if field?('l')
end
|
#display_line_number(tag) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/ripper-tags/vim_formatter.rb', line 79
def display_line_number(tag)
if field?('n') && tag[:line]
"\tline:%s" % tag[:line]
else
""
end
end
|
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/ripper-tags/vim_formatter.rb', line 102
def format(tag, name_field = :name)
"%s\t%s\t%s\t%s%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_language,
display_inheritance(tag),
]
end
|
13
14
15
16
17
18
|
# File 'lib/ripper-tags/vim_formatter.rb', line 13
def
<<-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
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 = ('q')
end
|
#supported_fields ⇒ Object
6
|
# File 'lib/ripper-tags/vim_formatter.rb', line 6
def supported_fields() ['l', 'n'] end
|
#supported_flags ⇒ Object
5
|
# File 'lib/ripper-tags/vim_formatter.rb', line 5
def supported_flags() ['q'] end
|
#with_output ⇒ Object
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
@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)
write_line(format(tag))
if include_qualified_names? && tag[:full_name] != tag[:name] && constant?(tag)
write_line(format(tag, :full_name))
end
end
|
#write_line(line) ⇒ Object
39
40
41
|
# File 'lib/ripper-tags/vim_formatter.rb', line 39
def write_line(line)
@queued_write << line
end
|