forked from Marketcircle/jiraSOAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yard-jiraSOAP.rb
66 lines (58 loc) · 2.32 KB
/
yard-jiraSOAP.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class MyAttributeHandler < YARD::Handlers::Ruby::AttributeHandler
handles method_call(:add_attributes)
namespace_only # just to be safe
# @return [Hash{Symbol=>String}] convert a parse method to an object type
CONVERT_TABLE = {
content:'String',
to_i:'Fixnum',
to_iso_date:'Time',
to_boolean:'Boolean',
contents_of_children:'Array<String>',
children_as_object:'PROBLEM?', #' emacs ruby-mode fail
children_as_objects:'Array<PROBLEM?>',
to_url:'URI::HTTP,NSURL',
to_natural_date:'String',
to_color_triple:'Array<String>',
to_colour_triple:'Array<String>'
}
process do
return if statement.class == YARD::Parser::Ruby::ReferenceNode # no args
statement.parameters.each { |array|
next if array == false
entry = array.first
jira_name = entry[0].jump(:tstring_content).source
name = entry[1].jump(:ident).source
# @todo fix the back-pedaling (Symbol->String->Symbol)
type = CONVERT_TABLE[entry[2].jump(:ident).source.to_sym]
if type.match /PROBLEM\?/
type_ext = []
entry[-1].traverse { |node|
type_ext << node.source if node.type == :const
}
type.sub! /PROBLEM\?/, type_ext.join('::')
end
read_object = make_method name, type, jira_name, array.docstring
write_object = make_method "#{name}=", type, jira_name, array.docstring
if type == 'Boolean'
truth_object = make_method "#{name}?", type, jira_name, array.docstring
end
namespace.attributes[:instance][name] = { read:read_object, write:write_object }
}
end
# @param [String] name
# @param [String] type
# @param [String] jira_name
# @param [String] docstring
# @return [YARD::CodeObjects::MethodObject]
def make_method name, type, jira_name, docstring
object = YARD::CodeObjects::MethodObject.new(namespace, name, :instance)
object.dynamic = true
object.explicit = false
object['generator'] = 'Generated by #add_attributes'
object.docstring = "Corresponds to `#{jira_name}` in the javadoc."
object.docstring += "\n\n#{docstring}" if docstring
object.docstring += '.' unless object.docstring[-1] == '.'
object.docstring.add_tag(YARD::Tags::Tag.new(:return, "", type))
object
end
end