Class: BitClust::ClassEntry
- Inherits:
-
Entry
show all
- Includes:
- Enumerable
- Defined in:
- lib/bitclust/classentry.rb
Overview
Represents a class, a module or a singleton object (like ARGF, main, etc.).
Defined Under Namespace
Classes: Parts
Constant Summary
Constants inherited
from Entry
Entry::BracketLink
Constants included
from NameUtils
NameUtils::CHAR_TO_MARK, NameUtils::CHAR_TO_NAME, NameUtils::CLASS_NAME_RE, NameUtils::CLASS_PATH_RE, NameUtils::CONST_PATH_RE, NameUtils::CONST_RE, NameUtils::GVAR_RE, NameUtils::LIBNAME_RE, NameUtils::MARK_TO_CHAR, NameUtils::MARK_TO_NAME, NameUtils::METHOD_NAME_RE, NameUtils::METHOD_SPEC_RE, NameUtils::MID, NameUtils::NAME_TO_CHAR, NameUtils::NAME_TO_MARK, NameUtils::TYPEMARK_RE
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Entry
#detail_source, #encoding, #loaded?, persistent_properties, property, #synopsis_source, #type_id
Methods included from NameUtils
build_method_id, classid2name, classname2id, classname?, decodeid, decodename_fs, decodename_url, display_typemark, encodeid, encodename_fs, encodename_rdocurl, encodename_url, functionname?, gvarname?, html_filename, libid2name, libname2id, libname?, method_spec?, methodid2classid, methodid2libid, methodid2mname, methodid2specparts, methodid2specstring, methodid2typechar, methodid2typemark, methodid2typename, methodname?, split_method_id, split_method_spec, typechar2mark, typechar2name, typechar?, typemark2char, typemark2name, typemark?, typename2char, typename2mark, typename?
Constructor Details
#initialize(db, id) ⇒ ClassEntry
Returns a new instance of ClassEntry.
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/bitclust/classentry.rb', line 25
def initialize(db, id)
super db
@id = id
if saved?
@entries = nil
@ancestors_checked = true
@s_ancestors_checked = true
else
@entries = []
@ancestors_checked = false
@s_ancestors_checked = false
end
init_properties
end
|
Instance Attribute Details
Returns the value of attribute id.
40
41
42
|
# File 'lib/bitclust/classentry.rb', line 40
def id
@id
end
|
Instance Method Details
#<=>(other) ⇒ Object
53
54
55
|
# File 'lib/bitclust/classentry.rb', line 53
def <=>(other)
@id <=> other.id
end
|
#==(other) ⇒ Object
Also known as:
eql?
42
43
44
45
|
# File 'lib/bitclust/classentry.rb', line 42
def ==(other)
return false if self.class != other.class
@id == other.id
end
|
473
474
475
|
# File 'lib/bitclust/classentry.rb', line 473
def _cmap
@_cmap ||= makemap('c', included_modules(), constants())
end
|
468
469
470
|
# File 'lib/bitclust/classentry.rb', line 468
def _imap
@_imap ||= makemap('i', included_modules(), instance_methods())
end
|
463
464
465
|
# File 'lib/bitclust/classentry.rb', line 463
def _smap
@_smap ||= makemap('s', extended_modules(), singleton_methods())
end
|
#add_method(m) ⇒ Object
269
270
271
272
|
# File 'lib/bitclust/classentry.rb', line 269
def add_method(m)
entries().push m
end
|
Add a alias c to the alias list.
169
170
171
|
# File 'lib/bitclust/classentry.rb', line 169
def alias(c)
aliases().push c
end
|
#alias? ⇒ Boolean
130
131
132
|
# File 'lib/bitclust/classentry.rb', line 130
def alias?
!! aliasof()
end
|
#ancestors ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/bitclust/classentry.rb', line 213
def ancestors
@ancestors ||=
if self.object? && superclass()
myself, *ancestors = superclass().ancestors
[ myself, included().map {|m| m.ancestors },
ancestors ].flatten
else
[ self, included().map {|m| m.ancestors },
superclass() ? superclass().ancestors : [] ].flatten
end
end
|
#check_ancestor_type ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/bitclust/classentry.rb', line 173
def check_ancestor_type
s = superclass()
if s and not s.class? and not s.dummy?
raise InvalidAncestor, "#{name()} inherits #{s.name} but it is a #{s.type} (class expected)"
end
included().each do |c|
unless c.module? or c.dummy?
raise InvalidAncestor, "#{name()} includes #{c.name} but it is a #{c.type} (module expected)"
end
end
extended().each do |c|
unless c.module? or c.dummy?
raise InvalidAncestor, "#{name()} extends #{c.name} but it is a #{c.type} (module expected)"
end
end
end
|
#check_ancestors_link(path = []) ⇒ Object
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/bitclust/classentry.rb', line 190
def check_ancestors_link(path = [])
return if @ancestors_checked
if path.include?(name())
raise InvalidLink, "ancestor link looped: #{path_string(path)}"
end
([superclass()] + included()).compact.each do |c|
path.push name()
c.check_ancestors_link path
path.pop
end
@ancestors_checked = true
end
|
#check_singleton_ancestors_link(path = []) ⇒ Object
203
204
205
206
207
208
209
210
211
|
# File 'lib/bitclust/classentry.rb', line 203
def check_singleton_ancestors_link(path = [])
return if @s_ancestors_checked
extended().each do |c|
path.push name()
c.check_singleton_ancestors_link path
path.pop
end
@s_ancestors_checked = true
end
|
#class? ⇒ Boolean
118
119
120
|
# File 'lib/bitclust/classentry.rb', line 118
def class?
type() == :class
end
|
#clear_cache ⇒ Object
458
459
460
|
# File 'lib/bitclust/classentry.rb', line 458
def clear_cache
@_smap = @_imap = @_cmap = nil
end
|
#constant?(name, inherit = true) ⇒ Boolean
396
397
398
399
400
401
402
|
# File 'lib/bitclust/classentry.rb', line 396
def constant?(name, inherit = true)
if inherit
ancestors().any? {|c| c.constant?(name, false) }
else
constants(0).detect {|m| m.name?(name) }
end
end
|
#constant_names ⇒ Object
440
441
442
|
# File 'lib/bitclust/classentry.rb', line 440
def constant_names
_index().keys.select {|name| /\A\:/ =~ name }.filter_map {|name| name[1..-1] }
end
|
#constants(level = 0) ⇒ Object
372
373
374
|
# File 'lib/bitclust/classentry.rb', line 372
def constants(level = 0)
entries(level).select(&:constant?).sort_by(&:sort_key)
end
|
#description ⇒ Object
454
455
456
|
# File 'lib/bitclust/classentry.rb', line 454
def description
description_text(source.split(/\n\n+/, 2)[0].strip)
end
|
#dummy? ⇒ Boolean
114
115
116
|
# File 'lib/bitclust/classentry.rb', line 114
def dummy?
not type()
end
|
#dynamic_extend(m, lib) ⇒ Object
Add a module m to the dynamically extended module list.
160
161
162
163
164
165
166
|
# File 'lib/bitclust/classentry.rb', line 160
def dynamic_extend(m, lib)
if m.library != lib
message = "dynamically extended module #{m.name} should be defined in the module #{lib.name}"
raise InvalidLibrary, message
end
dynamically_extended().push m
end
|
#dynamic_include(m, lib) ⇒ Object
Add a module m to the dynamically included module list.
151
152
153
154
155
156
157
|
# File 'lib/bitclust/classentry.rb', line 151
def dynamic_include(m, lib)
if m.library != lib
message = "dynamically included module #{m.name} should be defined in the module #{lib.name}"
raise InvalidLibrary, message
end
dynamically_included().push m
end
|
#dynamically_included_entries ⇒ Object
Public instance methods contributed by modules that are dynamically
included into this class (via # reopen + include:/include).
Unlike included, dynamically_included does not affect ancestors
or the method resolution order, so these methods are never returned by
+entries+/+partitioned_entries+. This method exists so that screens and
templates can list them separately, attributed to the module (and its
library) that defines them, without disturbing the MRO.
Only each module's own public instance methods are returned (i.e. its
entries(0) filtered like public_instance_methods); methods that the
dynamically included module itself inherits are not followed. If no
module has been dynamically included, this returns an empty array, so
output for classes without dynamic include is unaffected.
247
248
249
|
# File 'lib/bitclust/classentry.rb', line 247
def dynamically_included_entries
dynamically_included().flat_map {|m| m.public_instance_methods(0) }
end
|
#each(&block) ⇒ Object
265
266
267
|
# File 'lib/bitclust/classentry.rb', line 265
def each(&block)
entries().each(&block)
end
|
#entries(level = 0) ⇒ Object
Also known as:
methods
255
256
257
258
259
260
261
|
# File 'lib/bitclust/classentry.rb', line 255
def entries(level = 0)
@entries ||= @db.entries("method/#{@id}")\
.map {|ent| MethodEntry.new(@db, "#{@id}/#{ent}") }
ret = @entries || raise
(ancestors[1..level] || raise).each{|c| ret += c.entries }
ret
end
|
#error_class? ⇒ Boolean
134
135
136
137
138
139
140
|
# File 'lib/bitclust/classentry.rb', line 134
def error_class?
if alias?
aliasof.error_class?
else
ancestors.any?{|k| k.name == 'Exception' }
end
end
|
#extend(m) ⇒ Object
146
147
148
|
# File 'lib/bitclust/classentry.rb', line 146
def extend(m)
extended().push m
end
|
#extended_modules ⇒ Object
251
252
253
|
# File 'lib/bitclust/classentry.rb', line 251
def extended_modules
ancestors().select(&:class?).map(&:extended).flatten
end
|
#fetch_method(spec) ⇒ Object
421
422
423
424
|
# File 'lib/bitclust/classentry.rb', line 421
def fetch_method(spec)
get_method(spec) or
raise MethodNotFound, "no such method: #{spec}"
end
|
#fetch_methods(spec) ⇒ Object
416
417
418
419
|
# File 'lib/bitclust/classentry.rb', line 416
def fetch_methods(spec)
get_methods(spec) or
raise MethodNotFound, "no such method: #{spec}"
end
|
#get_method(spec) ⇒ Object
412
413
414
|
# File 'lib/bitclust/classentry.rb', line 412
def get_method(spec)
entries().detect {|m| spec.match?(m) }
end
|
#get_methods(spec) ⇒ Object
408
409
410
|
# File 'lib/bitclust/classentry.rb', line 408
def get_methods(spec)
entries().select {|m| spec.match?(m) }
end
|
49
50
51
|
# File 'lib/bitclust/classentry.rb', line 49
def hash
@id.hash
end
|
#include(m) ⇒ Object
142
143
144
|
# File 'lib/bitclust/classentry.rb', line 142
def include(m)
included().push m
end
|
#included_modules ⇒ Object
227
228
229
230
231
|
# File 'lib/bitclust/classentry.rb', line 227
def included_modules
list = ancestors().select(&:module?)
list.delete self
list
end
|
#inherited_method_specs ⇒ Object
448
449
450
451
452
|
# File 'lib/bitclust/classentry.rb', line 448
def inherited_method_specs
cname = name()
_index().map {|mname, specstr| MethodSpec.parse(specstr) }\
.reject {|spec| spec.klass == cname }.uniq
end
|
110
111
112
|
# File 'lib/bitclust/classentry.rb', line 110
def inspect
"\#<#{type()} #{@id}>"
end
|
#instance_method?(name, inherit = true) ⇒ Boolean
388
389
390
391
392
393
394
|
# File 'lib/bitclust/classentry.rb', line 388
def instance_method?(name, inherit = true)
if inherit
_imap().key?(name)
else
instance_methods(0).detect {|m| m.name?(name) }
end
end
|
#instance_method_names ⇒ Object
436
437
438
|
# File 'lib/bitclust/classentry.rb', line 436
def instance_method_names
_index().keys.select {|name| /\A\#/ =~ name }.filter_map {|name| name[1..-1] }
end
|
#instance_methods(level = 0) ⇒ Object
346
347
348
349
|
# File 'lib/bitclust/classentry.rb', line 346
def instance_methods(level = 0)
entries(level).select(&:instance_method?).sort_by(&:sort_key)
end
|
FIXME: implement class alias
77
78
79
|
# File 'lib/bitclust/classentry.rb', line 77
def labels
[label()]
end
|
#match_entry(t, mname) ⇒ Object
427
428
429
|
# File 'lib/bitclust/classentry.rb', line 427
def match_entry(t, mname)
_index()[t + mname]
end
|
#module? ⇒ Boolean
122
123
124
|
# File 'lib/bitclust/classentry.rb', line 122
def module?
type() == :module
end
|
#name ⇒ Object
Also known as:
label
57
58
59
|
# File 'lib/bitclust/classentry.rb', line 57
def name
classid2name(@id)
end
|
#name?(n) ⇒ Boolean
61
62
63
|
# File 'lib/bitclust/classentry.rb', line 61
def name?(n)
name() == n
end
|
#name_match?(re) ⇒ Boolean
70
71
72
|
# File 'lib/bitclust/classentry.rb', line 70
def name_match?(re)
re =~ name()
end
|
#object? ⇒ Boolean
126
127
128
|
# File 'lib/bitclust/classentry.rb', line 126
def object?
type() == :object
end
|
#orig_superclass ⇒ Object
FIXME: do not use superclass property aliasing (#6826)
96
|
# File 'lib/bitclust/classentry.rb', line 96
alias orig_superclass superclass
|
#partitioned_entries(level = 0) ⇒ Object
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/bitclust/classentry.rb', line 281
def partitioned_entries(level = 0)
s = []; spv = []
i = []; ipv = []; ipt = []
mf = []
c = []; v = []
redefined = []
added = []
undefined = []
nomethod = []
entries(level).sort_by(&:name).each do |m|
case m.kind
when :defined
case m.type
when :singleton_method
(m.public? ? s : spv).push m
when :instance_method
tmp = m.public? ? i : ipv
tmp = ipt if m.protected?
tmp.push m
when :module_function
mf.push m
when :constant
c.push m
when :special_variable
v.push m
else
raise "must not happen: m.type=#{m.type.inspect} (#{m.inspect})"
end
when :redefined
redefined.push m
when :added
added.push m
when :undefined
undefined.push m
when :nomethod
nomethod.push m
end
end
Parts.new(s,spv, i,ipv,ipt, mf, c, v, redefined, added, undefined, nomethod)
end
|
#private_instance_methods(level = 0) ⇒ Object
Also known as:
private_methods
361
362
363
364
|
# File 'lib/bitclust/classentry.rb', line 361
def private_instance_methods(level = 0)
entries(level).select(&:private_instance_method?).sort_by(&:sort_key)
end
|
#private_singleton_methods(level = 0) ⇒ Object
351
352
353
354
|
# File 'lib/bitclust/classentry.rb', line 351
def private_singleton_methods(level = 0)
entries(level).select(&:private_singleton_method?).sort_by(&:sort_key)
end
|
#protected_instance_methods(level = 0) ⇒ Object
368
369
370
|
# File 'lib/bitclust/classentry.rb', line 368
def protected_instance_methods(level = 0)
entries(level).select(&:protected_instance_method?).sort_by(&:sort_key)
end
|
#public_instance_methods(level = 0) ⇒ Object
356
357
358
359
|
# File 'lib/bitclust/classentry.rb', line 356
def public_instance_methods(level = 0)
entries(level).select(&:public_instance_method?).sort_by(&:sort_key)
end
|
#public_singleton_methods(level = 0) ⇒ Object
341
342
343
344
|
# File 'lib/bitclust/classentry.rb', line 341
def public_singleton_methods(level = 0)
entries(level).select(&:public_singleton_method?).sort_by(&:sort_key)
end
|
Return the real class name
66
67
68
|
# File 'lib/bitclust/classentry.rb', line 66
def realname
alias? ? aliasof.name : name
end
|
105
106
107
108
|
# File 'lib/bitclust/classentry.rb', line 105
def save
super
save_index
end
|
#singleton_method?(name, inherit = true) ⇒ Boolean
380
381
382
383
384
385
386
|
# File 'lib/bitclust/classentry.rb', line 380
def singleton_method?(name, inherit = true)
if inherit
_smap().key?(name)
else
singleton_methods(0).detect {|m| m.name?(name) }
end
end
|
#singleton_method_names ⇒ Object
431
432
433
434
|
# File 'lib/bitclust/classentry.rb', line 431
def singleton_method_names
_index().keys.select {|name| /\A\./ =~ name }.filter_map {|name| name[1..-1] }
end
|
#singleton_methods(level = 0) ⇒ Object
336
337
338
339
|
# File 'lib/bitclust/classentry.rb', line 336
def singleton_methods(level = 0)
entries(level).select(&:singleton_method?).sort_by(&:sort_key)
end
|
#special_variable?(name) ⇒ Boolean
404
405
406
|
# File 'lib/bitclust/classentry.rb', line 404
def special_variable?(name)
special_variables().detect {|m| m.name?(name) }
end
|
#special_variable_names ⇒ Object
444
445
446
|
# File 'lib/bitclust/classentry.rb', line 444
def special_variable_names
special_variables().map {|m| m.names }.flatten
end
|
#special_variables ⇒ Object
376
377
378
|
# File 'lib/bitclust/classentry.rb', line 376
def special_variables
entries().select(&:special_variable?).sort_by(&:sort_key)
end
|
#superclass ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/bitclust/classentry.rb', line 97
def superclass
if alias?
aliasof.superclass
else
orig_superclass
end
end
|