21700: Install Bundler system-wide in Rails postinst
[arvados.git] / sdk / ruby-google-api-client / yard / templates / default / module / setup.rb
1 lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../../lib'))
2 $LOAD_PATH.unshift(lib_dir)
3 $LOAD_PATH.uniq!
4 require 'yard-google-code'
5
6 include Helpers::ModuleHelper
7
8 def init
9   sections :header, :box_info, :pre_docstring, T('docstring'), :children,
10     :constant_summary, [T('docstring')], :inherited_constants,
11     :inherited_methods,
12     :methodmissing, [T('method_details')],
13     :attribute_details, [T('method_details')],
14     :method_details_list, [T('method_details')]
15 end
16
17 def pre_docstring
18   return if object.docstring.blank?
19   erb(:pre_docstring)
20 end
21
22 def children
23   @inner = [[:modules, []], [:classes, []]]
24   object.children.each do |child|
25     @inner[0][1] << child if child.type == :module
26     @inner[1][1] << child if child.type == :class
27   end
28   @inner.map! {|v| [v[0], run_verifier(v[1].sort_by {|o| o.name.to_s })] }
29   return if (@inner[0][1].size + @inner[1][1].size) == 0
30   erb(:children)
31 end
32
33 def methodmissing
34   mms = object.meths(:inherited => true, :included => true)
35   return unless @mm = mms.find {|o| o.name == :method_missing && o.scope == :instance }
36   erb(:methodmissing)
37 end
38
39 def method_listing(include_specials = true)
40   return @smeths ||= method_listing.reject {|o| special_method?(o) } unless include_specials
41   return @meths if @meths
42   @meths = object.meths(:inherited => false, :included => false)
43   @meths = sort_listing(prune_method_listing(@meths))
44   @meths
45 end
46
47 def special_method?(meth)
48   return true if meth.name(true) == '#method_missing'
49   return true if meth.constructor?
50   false
51 end
52
53 def attr_listing
54   return @attrs if @attrs
55   @attrs = []
56   [:class, :instance].each do |scope|
57     object.attributes[scope].each do |name, rw|
58       @attrs << (rw[:read] || rw[:write])
59     end
60   end
61   @attrs = sort_listing(prune_method_listing(@attrs, false))
62 end
63
64 def constant_listing
65   return @constants if @constants
66   @constants = object.constants(:included => false, :inherited => false)
67   @constants += object.cvars
68   @constants = run_verifier(@constants)
69   @constants
70 end
71
72 def sort_listing(list)
73   list.sort_by {|o| [o.scope.to_s, o.name.to_s.downcase] }
74 end
75
76 def docstring_full(obj)
77   docstring = ""
78   if obj.tags(:overload).size == 1 && obj.docstring.empty?
79     docstring = obj.tag(:overload).docstring
80   else
81     docstring = obj.docstring
82   end
83
84   if docstring.summary.empty? && obj.tags(:return).size == 1 && obj.tag(:return).text
85     docstring = Docstring.new(obj.tag(:return).text.gsub(/\A([a-z])/) {|x| x.upcase }.strip)
86   end
87
88   docstring
89 end
90
91 def docstring_summary(obj)
92   docstring_full(obj).summary
93 end
94
95 def groups(list, type = "Method")
96   if groups_data = object.groups
97     others = list.select {|m| !m.group }
98     groups_data.each do |name|
99       items = list.select {|m| m.group == name }
100       yield(items, name) unless items.empty?
101     end
102   else
103     others = []
104     group_data = {}
105     list.each do |meth|
106       if meth.group
107         (group_data[meth.group] ||= []) << meth
108       else
109         others << meth
110       end
111     end
112     group_data.each {|group, items| yield(items, group) unless items.empty? }
113   end
114
115   scopes(others) {|items, scope| yield(items, "#{scope.to_s.capitalize} #{type} Summary") }
116 end
117
118 def scopes(list)
119   [:class, :instance].each do |scope|
120     items = list.select {|m| m.scope == scope }
121     yield(items, scope) unless items.empty?
122   end
123 end
124
125 def mixed_into(object)
126   unless globals.mixed_into
127     globals.mixed_into = {}
128     list = run_verifier Registry.all(:class, :module)
129     list.each {|o| o.mixins.each {|m| (globals.mixed_into[m.path] ||= []) << o } }
130   end
131
132   globals.mixed_into[object.path] || []
133 end