/
setup.rb
129 lines (111 loc) · 3.45 KB
/
setup.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
include Helpers::ModuleHelper
def init
sections :header, :box_info, :pre_docstring, T('docstring'), :children,
:constant_summary, [T('docstring')], :inherited_constants,
:attribute_summary, [:item_summary],
:method_summary, [:item_summary], :inherited_methods,
:methodmissing, [T('method_details')],
:attribute_details, [T('method_details')],
:method_details_list, [T('method_details')]
end
def pre_docstring
return if object.docstring.blank?
erb(:pre_docstring)
end
def children
@inner = [[:modules, []], [:classes, []]]
object.children.each do |child|
@inner[0][1] << child if child.type == :module
@inner[1][1] << child if child.type == :class
end
@inner.map! {|v| [v[0], run_verifier(v[1].sort_by {|o| o.name.to_s })] }
return if (@inner[0][1].size + @inner[1][1].size) == 0
erb(:children)
end
def methodmissing
mms = object.meths(:inherited => true, :included => true)
return unless @mm = mms.find {|o| o.name == :method_missing && o.scope == :instance }
erb(:methodmissing)
end
def method_listing(include_specials = true)
return @smeths ||= method_listing.reject {|o| special_method?(o) } unless include_specials
return @meths if @meths
@meths = object.meths(:inherited => false, :included => false)
@meths = sort_listing(prune_method_listing(@meths))
@meths
end
def special_method?(meth)
return true if meth.name(true) == '#method_missing'
return true if meth.constructor?
false
end
def attr_listing
return @attrs if @attrs
@attrs = []
[:class, :instance].each do |scope|
object.attributes[scope].each do |name, rw|
@attrs << (rw[:read] || rw[:write])
end
end
@attrs = sort_listing(prune_method_listing(@attrs, false))
end
def constant_listing
return @constants if @constants
@constants = object.constants(:included => false, :inherited => false)
@constants += object.cvars
@constants = run_verifier(@constants)
@constants
end
def sort_listing(list)
list.sort_by {|o| [o.scope.to_s, o.name.to_s.downcase] }
end
def docstring_full(obj)
docstring = ""
if obj.tags(:overload).size == 1 && obj.docstring.empty?
docstring = obj.tag(:overload).docstring
else
docstring = obj.docstring
end
if docstring.summary.empty? && obj.tags(:return).size == 1 && obj.tag(:return).text
docstring = Docstring.new(obj.tag(:return).text.gsub(/\A([a-z])/) {|x| x.upcase }.strip)
end
docstring
end
def docstring_summary(obj)
docstring_full(obj).summary
end
def groups(list, type = "Method")
if groups_data = object.groups
others = list.select {|m| !m.group }
groups_data.each do |name|
items = list.select {|m| m.group == name }
yield(items, name) unless items.empty?
end
else
others = []
group_data = {}
list.each do |meth|
if meth.group
(group_data[meth.group] ||= []) << meth
else
others << meth
end
end
group_data.each {|group, items| yield(items, group) unless items.empty? }
end
scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type} Summary") }
end
def scopes(list)
[:class, :instance].each do |scope|
items = list.select {|m| m.scope == scope }
yield(items, scope) unless items.empty?
end
end
def mixed_into(object)
unless defined?(@@mixed_into) && @@mixed_into
@@mixed_into = {}
list = run_verifier Registry.all(:class, :module)
list.each {|o| o.mixins.each {|m| (@@mixed_into[m.path] ||= []) << o } }
end
@@mixed_into[object.path] || []
end