Class: BitClust::Subcommands::LookupCommand
Constant Summary
collapse
- TEMPLATE =
{
:library => {
:text => <<-End,
:html => <<-End
<dl>
<dt>type</dt><dd>library</dd>
<dt>name</dt><dd><%= entry.name %></dd>
<dt>classes</dt><dd><%= entry.classes.map {|c| c.name }.sort.join(', ') %></dd>
<dt>methods</dt><dd><%= entry.methods.map {|m| m.name }.sort.join(', ') %></dd>
</dl>
<%= compile_rd(entry.source) %>
End
},
:class => {
:text => <<-End,
:html => <<-End
<dl>
<dt>type</dt><dd>class</dd>
<dt>name</dt><dd><%= entry.name %></dd>
<dt>library</dt><dd><%= entry.library.name %></dd>
<dt>singleton_methods</dt><dd><%= entry.singleton_methods.map {|m| m.name }.sort.join(', ') %></dd>
<dt>instance_methods</dt><dd><%= entry.instance_methods.map {|m| m.name }.sort.join(', ') %></dd>
</dl>
<%= compile_rd(entry.source) %>
End
},
:method => {
:text => <<-End,
:html => <<-End
<dl>
<dt>type</dt><dd><%= entry.type %></dd>
<dt>name</dt><dd><%= entry.name %></dd>
<dt>names</dt><dd><%= entry.names.sort.join(', ') %></dd>
<dt>visibility</dt><dd><%= entry.visibility %></dd>
<dt>kind</dt><dd><%= entry.kind %></dd>
<dt>library</dt><dd><%= entry.library.name %></dd>
</dl>
<%= compile_rd(entry.source) %>
End
},
:function => {
:text => <<-End,
:html => <<-End
<dl>
<dt>kind</dt><dd><%= entry.kind %></dd>
<dt>header</dt><dd><%= entry.header %></dd>
<dt>filename</dt><dd><%= entry.filename %></dd>
</dl>
<%= compile_rd(entry.source) %>
End
}
}
Instance Method Summary
collapse
#align_progress_bar_title, #error, #help, #option_error, #srcdir_root
Constructor Details
Returns a new instance of LookupCommand.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/bitclust/subcommands/lookup_command.rb', line 15
def initialize
super
@format = :text
@type = nil
@key = nil
@parser.banner = "Usage: #{File.basename($0, '.*')} lookup (--library|--class|--method|--function) [--html] <key>"
@parser.on('--library=NAME', 'Lookup library.') {|name|
@type = :library
@key = name
}
@parser.on('--class=NAME', 'Lookup class.') {|name|
@type = :class
@key = name
}
@parser.on('--method=NAME', 'Lookup method.') {|name|
@type = :method
@key = name
}
@parser.on('--function=NAME', 'Lookup function. (C API)') {|name|
@type = :function
@key = name
}
@parser.on('--html', 'Show result in HTML.') {
@format = :html
}
end
|
Instance Method Details
#compile_rd(src) ⇒ Object
167
168
169
170
171
172
|
# File 'lib/bitclust/subcommands/lookup_command.rb', line 167
def compile_rd(src)
umap = URLMapper.new(:base_url => 'http://example.com',
:cgi_url => 'http://example.com/view')
compiler = RDCompiler.new(umap, 2)
compiler.compile(src)
end
|
#exec(argv, options) ⇒ Object
52
53
54
55
56
|
# File 'lib/bitclust/subcommands/lookup_command.rb', line 52
def exec(argv, options)
super
entry = fetch_entry(@db, @type, @key)
puts fill_template(get_template(@type, @format), entry)
end
|
#fetch_entry(db, type, key) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/bitclust/subcommands/lookup_command.rb', line 58
def fetch_entry(db, type, key)
case type
when :library
db.fetch_library(key)
when :class
db.fetch_class(key)
when :method
db.fetch_method(MethodSpec.parse(key))
when :function
db.fetch_function(key)
else
raise "must not happen: #{type.inspect}"
end
end
|
#fill_template(template, entry) ⇒ Object
73
74
75
|
# File 'lib/bitclust/subcommands/lookup_command.rb', line 73
def fill_template(template, entry)
ERB.new(template).result(binding())
end
|
#get_template(type, format) ⇒ Object
77
78
79
80
|
# File 'lib/bitclust/subcommands/lookup_command.rb', line 77
def get_template(type, format)
template = TEMPLATE[type][format]
TextUtils.unindent_block(template.lines).join('')
end
|
#parse(argv) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/bitclust/subcommands/lookup_command.rb', line 42
def parse(argv)
super
unless @type
error "one of --library/--class/--method/--function is required"
end
unless argv.empty?
error "too many arguments"
end
end
|