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 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
Class Method 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, 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
|
Class Method Details
21
22
23
|
# File 'lib/bitclust/classentry.rb', line 21
def ClassEntry.type_id
:class
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
|
426
427
428
|
# File 'lib/bitclust/classentry.rb', line 426
def _cmap
@_cmap ||= makemap('c', included_modules(), constants())
end
|
421
422
423
|
# File 'lib/bitclust/classentry.rb', line 421
def _imap
@_imap ||= makemap('i', included_modules(), instance_methods())
end
|
416
417
418
|
# File 'lib/bitclust/classentry.rb', line 416
def _smap
@_smap ||= makemap('s', extended_modules(), singleton_methods())
end
|
#add_method(m) ⇒ Object
249
250
251
252
|
# File 'lib/bitclust/classentry.rb', line 249
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
|
# 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
411
412
413
|
# File 'lib/bitclust/classentry.rb', line 411
def clear_cache
@_smap = @_imap = @_cmap = nil
end
|
#constant?(name, inherit = true) ⇒ Boolean
349
350
351
352
353
354
355
|
# File 'lib/bitclust/classentry.rb', line 349
def constant?(name, inherit = true)
if inherit
ancestors().any? {|c| c.constant?(name, false) }
else
constants(false).detect {|m| m.name?(name) }
end
end
|
#constant_names ⇒ Object
393
394
395
|
# File 'lib/bitclust/classentry.rb', line 393
def constant_names
_index().keys.select {|name| /\A\:/ =~ name }.map {|name| name[1..-1] }
end
|
#constants(level = 0) ⇒ Object
325
326
327
|
# File 'lib/bitclust/classentry.rb', line 325
def constants(level = 0)
entries(level).select(&:constant?).sort_by(&:sort_key)
end
|
#description ⇒ Object
407
408
409
|
# File 'lib/bitclust/classentry.rb', line 407
def description
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
|
#each(&block) ⇒ Object
245
246
247
|
# File 'lib/bitclust/classentry.rb', line 245
def each(&block)
entries().each(&block)
end
|
#entries(level = 0) ⇒ Object
Also known as:
methods
235
236
237
238
239
240
241
|
# File 'lib/bitclust/classentry.rb', line 235
def entries(level = 0)
@entries ||= @db.entries("method/#{@id}")\
.map {|ent| MethodEntry.new(@db, "#{@id}/#{ent}") }
ret = @entries
ancestors[1..level].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
231
232
233
|
# File 'lib/bitclust/classentry.rb', line 231
def extended_modules
ancestors().select(&:class?).map(&:extended).flatten
end
|
#fetch_method(spec) ⇒ Object
374
375
376
377
|
# File 'lib/bitclust/classentry.rb', line 374
def fetch_method(spec)
get_method(spec) or
raise MethodNotFound, "no such method: #{spec}"
end
|
#fetch_methods(spec) ⇒ Object
369
370
371
372
|
# File 'lib/bitclust/classentry.rb', line 369
def fetch_methods(spec)
get_methods(spec) or
raise MethodNotFound, "no such method: #{spec}"
end
|
#get_method(spec) ⇒ Object
365
366
367
|
# File 'lib/bitclust/classentry.rb', line 365
def get_method(spec)
entries().detect {|m| spec.match?(m) }
end
|
#get_methods(spec) ⇒ Object
361
362
363
|
# File 'lib/bitclust/classentry.rb', line 361
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
225
226
227
228
229
|
# File 'lib/bitclust/classentry.rb', line 225
def included_modules
list = ancestors().select(&:module?)
list.delete self
list
end
|
#inherited_method_specs ⇒ Object
401
402
403
404
405
|
# File 'lib/bitclust/classentry.rb', line 401
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
341
342
343
344
345
346
347
|
# File 'lib/bitclust/classentry.rb', line 341
def instance_method?(name, inherit = true)
if inherit
_imap().key?(name)
else
instance_methods(false).detect {|m| m.name?(name) }
end
end
|
#instance_method_names ⇒ Object
389
390
391
|
# File 'lib/bitclust/classentry.rb', line 389
def instance_method_names
_index().keys.select {|name| /\A\#/ =~ name }.map {|name| name[1..-1] }
end
|
#instance_methods(level = 0) ⇒ Object
303
304
305
306
|
# File 'lib/bitclust/classentry.rb', line 303
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
380
381
382
|
# File 'lib/bitclust/classentry.rb', line 380
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
# File 'lib/bitclust/classentry.rb', line 260
def partitioned_entries(level = 0)
s = []; spv = []
i = []; ipv = []
mf = []
c = []; v = []
added = []
undefined = []
entries(level).sort_by(&:name).each do |m|
case m.kind
when :defined, :redefined
case m.type
when :singleton_method
(m.public? ? s : spv).push m
when :instance_method
(m.public? ? i : ipv).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 :added
added.push m
when :undefined
undefined.push m
end
end
Parts.new(s,spv, i,ipv, mf, c, v, added, undefined)
end
|
#private_instance_methods(level = 0) ⇒ Object
Also known as:
private_methods
318
319
320
321
|
# File 'lib/bitclust/classentry.rb', line 318
def private_instance_methods(level = 0)
entries(level).select(&:private_instance_method?).sort_by(&:sort_key)
end
|
#private_singleton_methods(level = 0) ⇒ Object
308
309
310
311
|
# File 'lib/bitclust/classentry.rb', line 308
def private_singleton_methods(level = 0)
entries(level).select(&:private_singleton_method?).sort_by(&:sort_key)
end
|
#public_instance_methods(level = 0) ⇒ Object
313
314
315
316
|
# File 'lib/bitclust/classentry.rb', line 313
def public_instance_methods(level = 0)
entries(level).select(&:public_instance_method?).sort_by(&:sort_key)
end
|
#public_singleton_methods(level = 0) ⇒ Object
298
299
300
301
|
# File 'lib/bitclust/classentry.rb', line 298
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
333
334
335
336
337
338
339
|
# File 'lib/bitclust/classentry.rb', line 333
def singleton_method?(name, inherit = true)
if inherit
_smap().key?(name)
else
singleton_methods(false).detect {|m| m.name?(name) }
end
end
|
#singleton_method_names ⇒ Object
384
385
386
387
|
# File 'lib/bitclust/classentry.rb', line 384
def singleton_method_names
_index().keys.select {|name| /\A\./ =~ name }.map {|name| name[1..-1] }
end
|
#singleton_methods(level = 0) ⇒ Object
293
294
295
296
|
# File 'lib/bitclust/classentry.rb', line 293
def singleton_methods(level = 0)
entries(level).select(&:singleton_method?).sort_by(&:sort_key)
end
|
#special_variable?(name) ⇒ Boolean
357
358
359
|
# File 'lib/bitclust/classentry.rb', line 357
def special_variable?(name)
special_variables().detect {|m| m.name?(name) }
end
|
#special_variable_names ⇒ Object
397
398
399
|
# File 'lib/bitclust/classentry.rb', line 397
def special_variable_names
special_variables().map {|m| m.names }.flatten
end
|
#special_variables ⇒ Object
329
330
331
|
# File 'lib/bitclust/classentry.rb', line 329
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
|