sqlpostgres 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/Gemfile +8 -0
  2. data/Gemfile.lock +22 -0
  3. data/LICENSE.md +23 -0
  4. data/README.rdoc +59 -0
  5. data/Rakefile +32 -0
  6. data/VERSION +1 -0
  7. data/doc/BUGS +2 -0
  8. data/doc/examples/README +6 -0
  9. data/doc/examples/connection.rb +16 -0
  10. data/doc/examples/connection_auto.rb +22 -0
  11. data/doc/examples/connection_ctor.rb +18 -0
  12. data/doc/examples/connection_default.rb +15 -0
  13. data/doc/examples/connection_exec.rb +18 -0
  14. data/doc/examples/connection_manual.rb +12 -0
  15. data/doc/examples/connection_wrapped_new.rb +13 -0
  16. data/doc/examples/connection_wrapped_open.rb +13 -0
  17. data/doc/examples/cursor.rb +38 -0
  18. data/doc/examples/include_module.rb +9 -0
  19. data/doc/examples/include_module2.rb +12 -0
  20. data/doc/examples/insert.rb +30 -0
  21. data/doc/examples/insert2.rb +36 -0
  22. data/doc/examples/insert_bytea.rb +16 -0
  23. data/doc/examples/insert_bytea_array.rb +17 -0
  24. data/doc/examples/insert_default_values.rb +16 -0
  25. data/doc/examples/insert_insert.rb +16 -0
  26. data/doc/examples/insert_insert_default.rb +16 -0
  27. data/doc/examples/insert_insert_select.rb +20 -0
  28. data/doc/examples/insert_select.rb +20 -0
  29. data/doc/examples/interval.rb +17 -0
  30. data/doc/examples/savepoint.rb +38 -0
  31. data/doc/examples/select.rb +33 -0
  32. data/doc/examples/select2.rb +36 -0
  33. data/doc/examples/select_cross_join.rb +18 -0
  34. data/doc/examples/select_distinct.rb +18 -0
  35. data/doc/examples/select_distinct_on +19 -0
  36. data/doc/examples/select_for_update.rb +18 -0
  37. data/doc/examples/select_from.rb +17 -0
  38. data/doc/examples/select_from_subselect.rb +20 -0
  39. data/doc/examples/select_group_by.rb +19 -0
  40. data/doc/examples/select_having.rb +20 -0
  41. data/doc/examples/select_join_on.rb +18 -0
  42. data/doc/examples/select_join_using.rb +18 -0
  43. data/doc/examples/select_limit.rb +19 -0
  44. data/doc/examples/select_natural_join.rb +18 -0
  45. data/doc/examples/select_offset.rb +19 -0
  46. data/doc/examples/select_order_by.rb +20 -0
  47. data/doc/examples/select_select.rb +30 -0
  48. data/doc/examples/select_select_alias.rb +30 -0
  49. data/doc/examples/select_select_expression.rb +31 -0
  50. data/doc/examples/select_select_literal.rb +24 -0
  51. data/doc/examples/select_union.rb +21 -0
  52. data/doc/examples/select_where_array.rb +18 -0
  53. data/doc/examples/select_where_in.rb +18 -0
  54. data/doc/examples/select_where_string.rb +18 -0
  55. data/doc/examples/simple.rb +34 -0
  56. data/doc/examples/transaction.rb +30 -0
  57. data/doc/examples/transaction_abort.rb +30 -0
  58. data/doc/examples/transaction_commit.rb +34 -0
  59. data/doc/examples/translate_substitute_values.rb +17 -0
  60. data/doc/examples/update.rb +32 -0
  61. data/doc/examples/update2.rb +44 -0
  62. data/doc/examples/update_only.rb +17 -0
  63. data/doc/examples/update_set.rb +17 -0
  64. data/doc/examples/update_set_array.rb +16 -0
  65. data/doc/examples/update_set_bytea.rb +16 -0
  66. data/doc/examples/update_set_expression.rb +16 -0
  67. data/doc/examples/update_set_subselect.rb +20 -0
  68. data/doc/examples/update_where.rb +17 -0
  69. data/doc/examples/use_prefix.rb +8 -0
  70. data/doc/examples/use_prefix2.rb +11 -0
  71. data/doc/index.html +31 -0
  72. data/doc/insertexamples.rb +9 -0
  73. data/doc/makemanual +4 -0
  74. data/doc/makerdoc +5 -0
  75. data/doc/manual.dbk +622 -0
  76. data/lib/sqlpostgres/Connection.rb +198 -0
  77. data/lib/sqlpostgres/Cursor.rb +157 -0
  78. data/lib/sqlpostgres/Delete.rb +67 -0
  79. data/lib/sqlpostgres/Exceptions.rb +15 -0
  80. data/lib/sqlpostgres/Insert.rb +279 -0
  81. data/lib/sqlpostgres/NullConnection.rb +22 -0
  82. data/lib/sqlpostgres/PgBit.rb +73 -0
  83. data/lib/sqlpostgres/PgBox.rb +37 -0
  84. data/lib/sqlpostgres/PgCidr.rb +21 -0
  85. data/lib/sqlpostgres/PgCircle.rb +75 -0
  86. data/lib/sqlpostgres/PgInet.rb +21 -0
  87. data/lib/sqlpostgres/PgInterval.rb +208 -0
  88. data/lib/sqlpostgres/PgLineSegment.rb +37 -0
  89. data/lib/sqlpostgres/PgMacAddr.rb +21 -0
  90. data/lib/sqlpostgres/PgPath.rb +64 -0
  91. data/lib/sqlpostgres/PgPoint.rb +65 -0
  92. data/lib/sqlpostgres/PgPolygon.rb +56 -0
  93. data/lib/sqlpostgres/PgTime.rb +77 -0
  94. data/lib/sqlpostgres/PgTimeWithTimeZone.rb +98 -0
  95. data/lib/sqlpostgres/PgTimestamp.rb +93 -0
  96. data/lib/sqlpostgres/PgTwoPoints.rb +54 -0
  97. data/lib/sqlpostgres/PgType.rb +34 -0
  98. data/lib/sqlpostgres/PgWrapper.rb +41 -0
  99. data/lib/sqlpostgres/Savepoint.rb +98 -0
  100. data/lib/sqlpostgres/Select.rb +855 -0
  101. data/lib/sqlpostgres/Transaction.rb +120 -0
  102. data/lib/sqlpostgres/Translate.rb +436 -0
  103. data/lib/sqlpostgres/Update.rb +188 -0
  104. data/lib/sqlpostgres.rb +67 -0
  105. data/test/Assert.rb +72 -0
  106. data/test/Connection.test.rb +246 -0
  107. data/test/Cursor.test.rb +190 -0
  108. data/test/Delete.test.rb +68 -0
  109. data/test/Insert.test.rb +123 -0
  110. data/test/MockPGconn.rb +62 -0
  111. data/test/NullConnection.test.rb +32 -0
  112. data/test/PgBit.test.rb +98 -0
  113. data/test/PgBox.test.rb +108 -0
  114. data/test/PgCidr.test.rb +61 -0
  115. data/test/PgCircle.test.rb +107 -0
  116. data/test/PgInet.test.rb +61 -0
  117. data/test/PgInterval.test.rb +180 -0
  118. data/test/PgLineSegment.test.rb +108 -0
  119. data/test/PgMacAddr.test.rb +61 -0
  120. data/test/PgPath.test.rb +106 -0
  121. data/test/PgPoint.test.rb +100 -0
  122. data/test/PgPolygon.test.rb +95 -0
  123. data/test/PgTime.test.rb +120 -0
  124. data/test/PgTimeWithTimeZone.test.rb +117 -0
  125. data/test/PgTimestamp.test.rb +134 -0
  126. data/test/RandomThings.rb +25 -0
  127. data/test/Savepoint.test.rb +286 -0
  128. data/test/Select.test.rb +930 -0
  129. data/test/Test.rb +62 -0
  130. data/test/TestConfig.rb +21 -0
  131. data/test/TestSetup.rb +13 -0
  132. data/test/TestUtil.rb +92 -0
  133. data/test/Transaction.test.rb +275 -0
  134. data/test/Translate.test.rb +354 -0
  135. data/test/Update.test.rb +227 -0
  136. data/test/roundtrip.test.rb +565 -0
  137. data/test/test +34 -0
  138. data/tools/exampleinserter/ExampleInserter.rb +177 -0
  139. data/tools/rdoc/ChangeLog +796 -0
  140. data/tools/rdoc/EXAMPLE.rb +48 -0
  141. data/tools/rdoc/MANIFEST +58 -0
  142. data/tools/rdoc/Makefile +27 -0
  143. data/tools/rdoc/NEW_FEATURES +226 -0
  144. data/tools/rdoc/README +390 -0
  145. data/tools/rdoc/ToDo +6 -0
  146. data/tools/rdoc/contrib/Index +6 -0
  147. data/tools/rdoc/contrib/xslfo/ChangeLog +181 -0
  148. data/tools/rdoc/contrib/xslfo/README +106 -0
  149. data/tools/rdoc/contrib/xslfo/TODO +10 -0
  150. data/tools/rdoc/contrib/xslfo/convert.xsl +151 -0
  151. data/tools/rdoc/contrib/xslfo/demo/README +21 -0
  152. data/tools/rdoc/contrib/xslfo/demo/rdocfo +99 -0
  153. data/tools/rdoc/contrib/xslfo/fcm.xsl +54 -0
  154. data/tools/rdoc/contrib/xslfo/files.xsl +62 -0
  155. data/tools/rdoc/contrib/xslfo/labeled-lists.xsl +66 -0
  156. data/tools/rdoc/contrib/xslfo/lists.xsl +44 -0
  157. data/tools/rdoc/contrib/xslfo/modules.xsl +152 -0
  158. data/tools/rdoc/contrib/xslfo/rdoc.xsl +75 -0
  159. data/tools/rdoc/contrib/xslfo/source.xsl +66 -0
  160. data/tools/rdoc/contrib/xslfo/styles.xsl +69 -0
  161. data/tools/rdoc/contrib/xslfo/tables.xsl +67 -0
  162. data/tools/rdoc/contrib/xslfo/utils.xsl +21 -0
  163. data/tools/rdoc/debian/changelog +33 -0
  164. data/tools/rdoc/debian/compat +1 -0
  165. data/tools/rdoc/debian/control +20 -0
  166. data/tools/rdoc/debian/copyright +10 -0
  167. data/tools/rdoc/debian/dirs +2 -0
  168. data/tools/rdoc/debian/docs +2 -0
  169. data/tools/rdoc/debian/rdoc.1 +252 -0
  170. data/tools/rdoc/debian/rdoc.manpages +1 -0
  171. data/tools/rdoc/debian/rdoc.pod +149 -0
  172. data/tools/rdoc/debian/rules +9 -0
  173. data/tools/rdoc/dot/dot.rb +255 -0
  174. data/tools/rdoc/etc/rdoc.dtd +203 -0
  175. data/tools/rdoc/install.rb +137 -0
  176. data/tools/rdoc/markup/install.rb +43 -0
  177. data/tools/rdoc/markup/sample/sample.rb +42 -0
  178. data/tools/rdoc/markup/simple_markup/fragments.rb +323 -0
  179. data/tools/rdoc/markup/simple_markup/inline.rb +348 -0
  180. data/tools/rdoc/markup/simple_markup/lines.rb +147 -0
  181. data/tools/rdoc/markup/simple_markup/preprocess.rb +68 -0
  182. data/tools/rdoc/markup/simple_markup/to_html.rb +281 -0
  183. data/tools/rdoc/markup/simple_markup.rb +474 -0
  184. data/tools/rdoc/markup/test/AllTests.rb +2 -0
  185. data/tools/rdoc/markup/test/TestInline.rb +151 -0
  186. data/tools/rdoc/markup/test/TestParse.rb +411 -0
  187. data/tools/rdoc/rdoc/code_objects.rb +536 -0
  188. data/tools/rdoc/rdoc/diagram.rb +331 -0
  189. data/tools/rdoc/rdoc/generators/chm_generator.rb +112 -0
  190. data/tools/rdoc/rdoc/generators/html_generator.rb +1268 -0
  191. data/tools/rdoc/rdoc/generators/template/chm/chm.rb +86 -0
  192. data/tools/rdoc/rdoc/generators/template/html/html.rb +705 -0
  193. data/tools/rdoc/rdoc/generators/template/html/kilmer.rb +377 -0
  194. data/tools/rdoc/rdoc/generators/template/xml/rdf.rb +110 -0
  195. data/tools/rdoc/rdoc/generators/template/xml/xml.rb +110 -0
  196. data/tools/rdoc/rdoc/generators/xml_generator.rb +130 -0
  197. data/tools/rdoc/rdoc/options.rb +451 -0
  198. data/tools/rdoc/rdoc/parsers/parse_c.rb +287 -0
  199. data/tools/rdoc/rdoc/parsers/parse_f95.rb +118 -0
  200. data/tools/rdoc/rdoc/parsers/parse_rb.rb +2311 -0
  201. data/tools/rdoc/rdoc/parsers/parse_simple.rb +37 -0
  202. data/tools/rdoc/rdoc/parsers/parserfactory.rb +75 -0
  203. data/tools/rdoc/rdoc/rdoc.rb +219 -0
  204. data/tools/rdoc/rdoc/template.rb +234 -0
  205. data/tools/rdoc/rdoc/tokenstream.rb +25 -0
  206. data/tools/rdoc/rdoc.rb +9 -0
  207. metadata +291 -0
@@ -0,0 +1,536 @@
1
+ # We represent the various high-level code constructs that appear
2
+ # in Ruby programs: classes, modules, methods, and so on.
3
+
4
+ require 'rdoc/tokenstream'
5
+
6
+ module RDoc
7
+
8
+
9
+ # We contain the common stuff for contexts (which are containers)
10
+ # and other elements (methods, attributes and so on)
11
+ #
12
+ class CodeObject
13
+
14
+ # We are the model of the code, but we know that at some point
15
+ # we will be worked on by viewers. By implementing the Viewable
16
+ # protocol, viewers can associated themselves with these objects.
17
+
18
+ attr_accessor :viewer
19
+
20
+ # do we document ourselves?
21
+
22
+ attr_reader :document_self
23
+
24
+ def document_self=(val)
25
+ @document_self = val
26
+ if !val
27
+ remove_methods_etc
28
+ end
29
+ end
30
+
31
+ # do we document ourselves and our children
32
+
33
+ attr_reader :document_children
34
+
35
+ def document_children=(val)
36
+ @document_children = val
37
+ if !val
38
+ remove_classes_and_modules
39
+ end
40
+ end
41
+
42
+ # Do we _force_ documentation, even is we wouldn't normally show the entity
43
+ attr_accessor :force_documentation
44
+
45
+ # Default callbacks to nothing, but this is overridden for classes
46
+ # and modules
47
+ def remove_classes_and_modules
48
+ end
49
+
50
+ def remove_methods_etc
51
+ end
52
+
53
+ def initialize
54
+ @document_self = true
55
+ @document_children = true
56
+ @force_documentation = false
57
+ end
58
+
59
+ # Access the code object's comment
60
+ attr_reader :comment
61
+
62
+ # Update the comment, but don't overwrite a real comment
63
+ # with an empty one
64
+ def comment=(comment)
65
+ @comment = comment unless comment.empty?
66
+ end
67
+
68
+ # There's a wee trick we pull. Comment blocks can have directives that
69
+ # override the stuff we extract during the parse. So, we have a special
70
+ # class method, attr_overridable, that lets code objects list
71
+ # those directives. Wehn a comment is assigned, we then extract
72
+ # out any matching directives and update our object
73
+
74
+ def CodeObject.attr_overridable(name, *aliases)
75
+ @overridables ||= {}
76
+
77
+ attr_accessor name
78
+
79
+ aliases.unshift name
80
+ aliases.each do |directive_name|
81
+ @overridables[directive_name.to_s] = name
82
+ end
83
+ end
84
+ end
85
+
86
+ # A Context is something that can hold modules, classes, methods,
87
+ # attributes, aliases, requires, and includes. Classes, modules, and
88
+ # files are all Contexts.
89
+
90
+ class Context < CodeObject
91
+ attr_reader :name, :method_list, :attributes, :aliases
92
+ attr_reader :requires, :includes, :in_files
93
+ attr_accessor :parent
94
+
95
+
96
+ def initialize
97
+ super()
98
+
99
+ @in_files = []
100
+
101
+ @name ||= "unknown"
102
+ @comment ||= ""
103
+ @parent = nil
104
+ @visibility = :public
105
+
106
+ initialize_methods_etc
107
+ initialize_classes_and_modules
108
+ end
109
+
110
+ # map the class hash to an array externally
111
+ def classes
112
+ @classes.values
113
+ end
114
+
115
+ # map the module hash to an array externally
116
+ def modules
117
+ @modules.values
118
+ end
119
+
120
+ # Change the default visibility for new methods
121
+ def ongoing_visibility=(vis)
122
+ @visibility = vis
123
+ end
124
+
125
+ # Given an array +methods+ of method names, set the
126
+ # visibility of the corresponding AnyMethod object
127
+
128
+ def set_visibility_for(methods, vis)
129
+ @method_list.each_with_index do |m,i|
130
+ if methods.include?(m.name)
131
+ m.visibility = vis
132
+ end
133
+ end
134
+ end
135
+
136
+ # Record the file that we happen to find it in
137
+ def record_location(toplevel)
138
+ @in_files << toplevel unless @in_files.include?(toplevel)
139
+ end
140
+
141
+ def add_class(class_type, name, superclass)
142
+ add_class_or_module(@classes, class_type, name, superclass)
143
+ end
144
+
145
+ def add_module(class_type, name)
146
+ add_class_or_module(@modules, class_type, name, nil)
147
+ end
148
+
149
+ def add_method(a_method)
150
+ puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG
151
+ a_method.visibility = @visibility
152
+ add_to(@method_list, a_method)
153
+ end
154
+
155
+ def add_attribute(an_attribute)
156
+ add_to(@attributes, an_attribute)
157
+ end
158
+
159
+ def add_alias(an_alias)
160
+ meth = find_method_named(an_alias.old_name)
161
+ if meth
162
+ new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
163
+ new_meth.is_alias_for = meth
164
+ new_meth.singleton = meth.singleton
165
+ new_meth.params = meth.params
166
+ new_meth.comment = "Alias for \##{meth.name}"
167
+ meth.add_alias(new_meth)
168
+ add_method(new_meth)
169
+ else
170
+ add_to(@aliases, an_alias)
171
+ end
172
+ end
173
+
174
+ def add_include(an_include)
175
+ add_to(@includes, an_include)
176
+ end
177
+
178
+ # Requires always get added to the top-level (file) context
179
+ def add_require(a_require)
180
+ if self.kind_of? TopLevel
181
+ add_to(@requires, a_require)
182
+ else
183
+ parent.add_require(a_require)
184
+ end
185
+ end
186
+
187
+ def add_class_or_module(collection, class_type, name, superclass=nil)
188
+ cls = collection[name]
189
+ if cls
190
+ puts "Reusing class/module #{name}" if $DEBUG
191
+ else
192
+ cls = class_type.new(name, superclass)
193
+ puts "Adding class/module #{name} to #@name" if $DEBUG
194
+ collection[name] = cls
195
+ cls.parent = self
196
+ end
197
+ cls
198
+ end
199
+
200
+ def add_to(array, thing)
201
+ array << thing if @document_self
202
+ thing.parent = self
203
+ end
204
+
205
+ # If a class's documentation is turned off after we've started
206
+ # collecting methods etc., we need to remove the ones
207
+ # we have
208
+
209
+ def remove_methods_etc
210
+ initialize_methods_etc
211
+ end
212
+
213
+ def initialize_methods_etc
214
+ @method_list = []
215
+ @attributes = []
216
+ @aliases = []
217
+ @requires = []
218
+ @includes = []
219
+ end
220
+
221
+ # and remove classes and modules when we see a :nodoc: all
222
+ def remove_classes_and_modules
223
+ initialize_classes_and_modules
224
+ end
225
+
226
+ def initialize_classes_and_modules
227
+ @classes = {}
228
+ @modules = {}
229
+ end
230
+
231
+ # Iterate over all the classes and modules in
232
+ # this object
233
+
234
+ def each_classmodule
235
+ @modules.each_value {|m| yield m}
236
+ @classes.each_value {|c| yield c}
237
+ end
238
+
239
+ def each_method
240
+ @method_list.each {|m| yield m}
241
+ end
242
+
243
+ def each_attribute
244
+ @attributes.each {|a| yield a}
245
+ end
246
+
247
+ # Return the toplevel that owns us
248
+
249
+ def toplevel
250
+ return @toplevel if defined? @toplevel
251
+ @toplevel = self
252
+ @toplevel = @toplevel.parent until TopLevel === @toplevel
253
+ @toplevel
254
+ end
255
+
256
+ # allow us to sort modules by name
257
+ def <=>(other)
258
+ name <=> other.name
259
+ end
260
+
261
+ private
262
+
263
+ # Find a named method, or return nil
264
+ def find_method_named(name)
265
+ @method_list.find {|m| m.name == name}
266
+ end
267
+
268
+ end
269
+
270
+
271
+ # A TopLevel context is a source file
272
+
273
+ class TopLevel < Context
274
+ attr_accessor :file_stat
275
+ attr_accessor :file_relative_name
276
+ attr_accessor :file_absolute_name
277
+ attr_accessor :diagram
278
+
279
+ @@all_classes = {}
280
+ @@all_modules = {}
281
+
282
+ def TopLevel::reset
283
+ @@all_classes = {}
284
+ @@all_modules = {}
285
+ end
286
+
287
+ def initialize(file_name)
288
+ super()
289
+ @name = "TopLevel"
290
+ @file_relative_name = file_name
291
+ @file_absolute_name = file_name
292
+ @file_stat = File.stat(file_name)
293
+ @diagram = nil
294
+ end
295
+
296
+ def full_name
297
+ nil
298
+ end
299
+
300
+ # Adding a class or module to a TopLevel is special, as we only
301
+ # want one copy of a particular top-level class. For example,
302
+ # if both file A and file B implement class C, we only want one
303
+ # ClassModule object for C. This code arranges to share
304
+ # classes and modules between files.
305
+
306
+ def add_class_or_module(collection, class_type, name, superclass)
307
+ cls = collection[name]
308
+ if cls
309
+ puts "Reusing class/module #{name}" if $DEBUG
310
+ else
311
+ if class_type == NormalModule
312
+ all = @@all_modules
313
+ else
314
+ all = @@all_classes
315
+ end
316
+ cls = all[name]
317
+ if !cls
318
+ cls = class_type.new(name, superclass)
319
+ all[name] = cls
320
+ end
321
+ puts "Adding class/module #{name} to #@name" if $DEBUG
322
+ collection[name] = cls
323
+ cls.parent = self
324
+ end
325
+ cls
326
+ end
327
+
328
+ def TopLevel.all_classes_and_modules
329
+ @@all_classes.values + @@all_modules.values
330
+ end
331
+
332
+ def TopLevel.find_class_named(name)
333
+ @@all_classes.each_value do |c|
334
+ res = c.find_class_named(name)
335
+ return res if res
336
+ end
337
+ nil
338
+ end
339
+ end
340
+
341
+ # ClassModule is the base class for objects representing either a
342
+ # class or a module.
343
+
344
+ class ClassModule < Context
345
+
346
+ attr_reader :superclass
347
+ attr_accessor :diagram
348
+
349
+ def initialize(name, superclass = nil)
350
+ @name = name
351
+ @diagram = nil
352
+ @superclass = superclass
353
+ @comment = ""
354
+ super()
355
+ end
356
+
357
+ # Return the fully qualified name of this class or module
358
+ def full_name
359
+ if @parent && @parent.full_name
360
+ @parent.full_name + "::" + @name
361
+ else
362
+ @name
363
+ end
364
+ end
365
+
366
+ def http_url(prefix)
367
+ path = full_name.split("::")
368
+ File.join(prefix, *path) + ".html"
369
+ end
370
+
371
+ # Return +true+ if this object represents a module
372
+ def is_module?
373
+ false
374
+ end
375
+
376
+ # to_s is simply for debugging
377
+ def to_s
378
+ res = self.class.name + ": " + @name
379
+ res << @comment.to_s
380
+ res << super
381
+ res
382
+ end
383
+
384
+ def find_class_named(name)
385
+ return self if full_name == name
386
+ @classes.each_value {|c| return c if c.find_class_named(name) }
387
+ nil
388
+ end
389
+ end
390
+
391
+ # Anonymous classes
392
+ class AnonClass < ClassModule
393
+ end
394
+
395
+ # Normal classes
396
+ class NormalClass < ClassModule
397
+ end
398
+
399
+ # Singleton classes
400
+ class SingleClass < ClassModule
401
+ end
402
+
403
+ # Module
404
+ class NormalModule < ClassModule
405
+ def is_module?
406
+ true
407
+ end
408
+ end
409
+
410
+
411
+ # AnyMethod is the base class for objects representing methods
412
+
413
+ class AnyMethod < CodeObject
414
+ attr_accessor :name
415
+ attr_accessor :parent
416
+ attr_accessor :visibility
417
+ attr_accessor :block_params
418
+ attr_accessor :dont_rename_initialize
419
+ attr_accessor :singleton
420
+ attr_reader :aliases # list of other names for this method
421
+ attr_accessor :is_alias_for # or a method we're aliasing
422
+
423
+ attr_overridable :params, :param, :parameters, :parameter
424
+
425
+ include TokenStream
426
+
427
+ def initialize(text, name)
428
+ super()
429
+ @text = text
430
+ @name = name
431
+ @token_stream = nil
432
+ @visibility = :public
433
+ @dont_rename_initialize = false
434
+ @block_params = nil
435
+ @aliases = []
436
+ @is_alias_for = nil
437
+ @comment = ""
438
+ end
439
+
440
+ def <=>(other)
441
+ @name <=> other.name
442
+ end
443
+
444
+ def to_s
445
+ res = self.class.name + ": " + @name + " (" + @text + ")\n"
446
+ res << @comment.to_s
447
+ res
448
+ end
449
+
450
+ def param_seq
451
+ p = params.gsub(/\s*\#.*/, '')
452
+ p = p.tr("\n", " ").squeeze(" ")
453
+ p = "(" + p + ")" unless p[0] == ?(
454
+
455
+ if (block = block_params)
456
+ block.gsub!(/\s*\#.*/, '')
457
+ block = block.tr("\n", " ").squeeze(" ")
458
+ if block[0] == ?(
459
+ block.sub!(/^\(/, '').sub!(/\)/, '')
460
+ end
461
+ p << " {|#{block}| ...}"
462
+ end
463
+ p
464
+ end
465
+
466
+ def add_alias(method)
467
+ @aliases << method
468
+ end
469
+ end
470
+
471
+
472
+ # Represent an alias, which is an old_name/ new_name pair associated
473
+ # with a particular context
474
+ class Alias < CodeObject
475
+ attr_accessor :parent, :text, :old_name, :new_name, :comment
476
+
477
+ def initialize(text, old_name, new_name, comment)
478
+ super()
479
+ @text = text
480
+ @old_name = old_name
481
+ @new_name = new_name
482
+ self.comment = comment
483
+ end
484
+
485
+ def to_s
486
+ "alias: #{self.old_name} -> #{self.new_name}\n#{self.comment}"
487
+ end
488
+ end
489
+
490
+ # Represent attributes
491
+ class Attr < CodeObject
492
+ attr_accessor :parent, :text, :name, :rw
493
+
494
+ def initialize(text, name, rw, comment)
495
+ super()
496
+ @text = text
497
+ @name = name
498
+ @rw = rw
499
+ self.comment = comment
500
+ end
501
+
502
+ def to_s
503
+ "attr: #{self.name} #{self.rw}\n#{self.comment}"
504
+ end
505
+
506
+ def <=>(other)
507
+ self.name <=> other.name
508
+ end
509
+ end
510
+
511
+ # a required file
512
+
513
+ class Require < CodeObject
514
+ attr_accessor :parent, :name
515
+
516
+ def initialize(name, comment)
517
+ super()
518
+ @name = name.gsub(/'|"/, "") #'
519
+ self.comment = comment
520
+ end
521
+
522
+ end
523
+
524
+ # an included module
525
+ class Include < CodeObject
526
+ attr_accessor :parent, :name
527
+
528
+ def initialize(name, comment)
529
+ super()
530
+ @name = name
531
+ self.comment = comment
532
+ end
533
+
534
+ end
535
+
536
+ end