Class: BitClust::MethodEntry
Overview
Entry for methods(instance methods/singleton methods/module_functions),
constants and special variables(like $!).
Constant Summary
collapse
- KIND_NUM =
{:defined => 0, :redefined => 1, :added => 2,
:undefined => 3, :nomethod => 4}
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, #save, #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
Returns a new instance of MethodEntry.
25
26
27
28
29
|
# File 'lib/bitclust/methodentry.rb', line 25
def initialize(db, id)
super db
@id = id
init_properties
end
|
Instance Attribute Details
Returns the value of attribute id.
31
32
33
|
# File 'lib/bitclust/methodentry.rb', line 31
def id
@id
end
|
103
104
105
|
# File 'lib/bitclust/methodentry.rb', line 103
def klass
@klass ||= @db.fetch_class_id(methodid2classid(@id))
end
|
97
98
99
|
# File 'lib/bitclust/methodentry.rb', line 97
def library
@library ||= @db.fetch_library_id(methodid2libid(@id))
end
|
Instance Method Details
#<=>(other) ⇒ Object
44
45
46
|
# File 'lib/bitclust/methodentry.rb', line 44
def <=>(other)
sort_key() <=> other.sort_key
end
|
#==(other) ⇒ Object
Also known as:
eql?
33
34
35
36
|
# File 'lib/bitclust/methodentry.rb', line 33
def ==(other)
return false if self.class != other.class
@id == other.id
end
|
#added? ⇒ Boolean
333
334
335
|
# File 'lib/bitclust/methodentry.rb', line 333
def added?
kind() == :added
end
|
#constant? ⇒ Boolean
321
322
323
|
# File 'lib/bitclust/methodentry.rb', line 321
def constant?
typename() == :constant
end
|
#defined? ⇒ Boolean
329
330
331
|
# File 'lib/bitclust/methodentry.rb', line 329
def defined?
kind() == :defined
end
|
#description ⇒ Object
351
352
353
354
355
356
|
# File 'lib/bitclust/methodentry.rb', line 351
def description
paragraphs = source.split(/\n\n+/).drop(1)
para = paragraphs.find {|p| !p.start_with?('@', '{:') } || paragraphs.first || ''
description_text(para)
end
|
#display_label ⇒ Object
bitclust#250: label の表示専用版(module function は 4.0 以降 "?." で
表示)。label 自身は refsdatabase.rb の [[a:...]] アンカーキーや
bitclust methods --diff の突き合わせが literal ".#" 前提で使うので
変えない -- テンプレート側の実際の表示箇所だけがこちらを呼ぶ
152
153
154
155
|
# File 'lib/bitclust/methodentry.rb', line 152
def display_label
c, t, m, _lib = methodid2specparts(@id)
"#{t == '$' ? '' : c}#{display_typemark}#{m}"
end
|
#display_short_label ⇒ Object
bitclust#250: short_label の表示専用版。short_label 自身の唯一の
呼び出し元(htmlutils.rb の link_to_method)は display_short_label に
切り替え済みだが、short_label 自体は同じ理由(識別子的な使い方をする
将来のコードのため)で変えない
166
167
168
169
|
# File 'lib/bitclust/methodentry.rb', line 166
def display_short_label
_c, t, m, _lib = methodid2specparts(@id)
"#{t == '#' ? '' : display_typemark}#{m}"
end
|
#display_title_labels ⇒ Object
bitclust#250: title_labels の表示専用版(
タグ・見出しで使う)
208
209
210
211
|
# File 'lib/bitclust/methodentry.rb', line 208
def display_title_labels
c, t, _m, _lib = methodid2specparts(@id)
names().map {|name| "#{t == '$' ? '' : c}#{display_typemark}#{name}" }
end
|
#display_typemark ⇒ Object
bitclust#250: 表示専用の typemark。DB のバージョンが 4.0 以降なら
module function の "." を "?." にする(それ以外の typemark は不変)。
typemark 自体(識別子として使う方)は変えない -- URL・spec 文字列・
refsdatabase のアンカーキー等はすべて typemark() 経由のまま
82
83
84
|
# File 'lib/bitclust/methodentry.rb', line 82
def display_typemark
NameUtils.display_typemark(typemark(), @db.propget('version'))
end
|
#fill_since(name, version) ⇒ Object
name の since が未設定の場合のみ version を追加する。追加したら true、
既に値があって何もしなければ false を返す
238
239
240
|
# File 'lib/bitclust/methodentry.rb', line 238
def fill_since(name, version)
fill_version_token(:since_by_name, :since_of, name, version)
end
|
#fill_until(name, version) ⇒ Object
243
244
245
|
# File 'lib/bitclust/methodentry.rb', line 243
def fill_until(name, version)
fill_version_token(:until_by_name, :until_of, name, version)
end
|
40
41
42
|
# File 'lib/bitclust/methodentry.rb', line 40
def hash
@id.hash
end
|
171
172
173
|
# File 'lib/bitclust/methodentry.rb', line 171
def index_id
"#{methodid2typechar(@id)}_#{encodename_fs(name).gsub(/=/, '--')}".upcase
end
|
129
130
131
132
|
# File 'lib/bitclust/methodentry.rb', line 129
def inspect
c, t, _m, _lib = methodid2specparts(@id)
"\#<method #{c}#{t}#{names().join(',')}>"
end
|
#instance_method? ⇒ Boolean
316
317
318
319
|
# File 'lib/bitclust/methodentry.rb', line 316
def instance_method?
t = typename()
t == :instance_method or t == :module_function
end
|
143
144
145
146
|
# File 'lib/bitclust/methodentry.rb', line 143
def label
c, t, m, _lib = methodid2specparts(@id)
"#{t == '$' ? '' : c}#{t}#{m}"
end
|
193
194
195
196
|
# File 'lib/bitclust/methodentry.rb', line 193
def labels
c, t, _m, _lib = methodid2specparts(@id)
names().map {|name| "#{c}#{t}#{name}" }
end
|
55
56
57
|
# File 'lib/bitclust/methodentry.rb', line 55
def name
methodid2mname(@id)
end
|
#name?(name) ⇒ Boolean
213
214
215
|
# File 'lib/bitclust/methodentry.rb', line 213
def name?(name)
names().include?(name)
end
|
#name_match?(re) ⇒ Boolean
271
272
273
|
# File 'lib/bitclust/methodentry.rb', line 271
def name_match?(re)
names().any? {|n| re =~ n }
end
|
#nomethod? ⇒ Boolean
説明のためだけに記載されていて実際には定義されていないメソッド
(ソースの @nomethod メタデータ行で指定する)
347
348
349
|
# File 'lib/bitclust/methodentry.rb', line 347
def nomethod?
kind() == :nomethod
end
|
#private? ⇒ Boolean
287
288
289
|
# File 'lib/bitclust/methodentry.rb', line 287
def private?
visibility() == :private
end
|
#private_instance_method? ⇒ Boolean
303
304
305
|
# File 'lib/bitclust/methodentry.rb', line 303
def private_instance_method?
instance_method? and private?
end
|
#private_singleton_method? ⇒ Boolean
295
296
297
|
# File 'lib/bitclust/methodentry.rb', line 295
def private_singleton_method?
singleton_method? and private?
end
|
#protected? ⇒ Boolean
283
284
285
|
# File 'lib/bitclust/methodentry.rb', line 283
def protected?
visibility() == :protected
end
|
#protected_instance_method? ⇒ Boolean
307
308
309
|
# File 'lib/bitclust/methodentry.rb', line 307
def protected_instance_method?
instance_method? and protected?
end
|
#public? ⇒ Boolean
279
280
281
|
# File 'lib/bitclust/methodentry.rb', line 279
def public?
visibility() != :private && visibility() != :protected
end
|
#public_instance_method? ⇒ Boolean
299
300
301
|
# File 'lib/bitclust/methodentry.rb', line 299
def public_instance_method?
instance_method? and public?
end
|
#public_singleton_method? ⇒ Boolean
291
292
293
|
# File 'lib/bitclust/methodentry.rb', line 291
def public_singleton_method?
singleton_method? and public?
end
|
#rbs_signature_overloads ⇒ Object
rbs_sig(JSON)をオーバーロード配列に戻す。現行形式は
"params":..., "arity":..., "block":...]}
で、セグメント行列そのものの配列だった旧形式の DB は segments だけの
オーバーロード列に読み替える。property が無い古い DB(nil)・
シグネチャ無しで保存された空文字列・未保存エントリの "(uninitialized)"
センチネル・壊れた JSON はすべて nil(= 表示しない)に落として
描画側を守る
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/bitclust/methodentry.rb', line 182
def rbs_signature_overloads
json = rbs_sig()
return nil unless json && (json.start_with?('{') || json.start_with?('['))
data = JSON.parse(json)
overloads = data.is_a?(Hash) ? data['overloads']
: data.map {|segments| {'segments' => segments} }
overloads.is_a?(Array) && !overloads.empty? ? overloads : nil
rescue JSON::ParserError
nil
end
|
#really_public? ⇒ Boolean
275
276
277
|
# File 'lib/bitclust/methodentry.rb', line 275
def really_public?
visibility() == :public
end
|
#redefined? ⇒ Boolean
337
338
339
|
# File 'lib/bitclust/methodentry.rb', line 337
def redefined?
kind() == :redefined
end
|
#short_label ⇒ Object
157
158
159
160
|
# File 'lib/bitclust/methodentry.rb', line 157
def short_label
_c, t, m, _lib = methodid2specparts(@id)
"#{t == '#' ? '' : t}#{m}"
end
|
#since_map ⇒ Object
228
229
230
|
# File 'lib/bitclust/methodentry.rb', line 228
def since_map
decode_version_tokens(since_by_name)
end
|
#since_of(name) ⇒ Object
名前別 since/until(bitclust#132)。名前ごとに別バージョンで
追加/削除されうる別名(例: alias)を区別して記録する
220
221
222
|
# File 'lib/bitclust/methodentry.rb', line 220
def since_of(name)
since_map[name]
end
|
#singleton_method? ⇒ Boolean
311
312
313
314
|
# File 'lib/bitclust/methodentry.rb', line 311
def singleton_method?
t = typename()
t == :singleton_method or t == :module_function
end
|
51
52
53
|
# File 'lib/bitclust/methodentry.rb', line 51
def sort_key
[label(), KIND_NUM[kind()]]
end
|
134
135
136
137
|
# File 'lib/bitclust/methodentry.rb', line 134
def spec
c, t, m, lib = methodid2specparts(@id)
MethodSpec.new(c, t, m, lib)
end
|
#spec_string ⇒ Object
139
140
141
|
# File 'lib/bitclust/methodentry.rb', line 139
def spec_string
methodid2specstring(@id)
end
|
#special_variable? ⇒ Boolean
325
326
327
|
# File 'lib/bitclust/methodentry.rb', line 325
def special_variable?
typename() == :special_variable
end
|
#title_labels ⇒ Object
Every name of this entry, formatted the same way as #label (i.e.
without the redundant class prefix on special variables such as $!,
unlike #labels). Used where all aliases of a method need to be listed
together, e.g. the
of its page.
202
203
204
205
|
# File 'lib/bitclust/methodentry.rb', line 202
def title_labels
c, t, _m, _lib = methodid2specparts(@id)
names().map {|name| "#{t == '$' ? '' : c}#{t}#{name}" }
end
|
#type_label ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/bitclust/methodentry.rb', line 86
def type_label
case typemark()
when '.' then 'singleton method'
when '#' then 'instance method'
when '.#' then 'module function'
when '::' then 'constant'
when '$' then 'variable'
else raise "invalid typemark: #{typemark().inspect}"
end
end
|
74
75
76
|
# File 'lib/bitclust/methodentry.rb', line 74
def typechar
methodid2typechar(@id)
end
|
70
71
72
|
# File 'lib/bitclust/methodentry.rb', line 70
def typemark
methodid2typemark(@id)
end
|
#typename ⇒ Object
Also known as:
type
typename = :singleton_method
| :instance_method
| :module_function
| :constant
| :special_variable
64
65
66
|
# File 'lib/bitclust/methodentry.rb', line 64
def typename
methodid2typename(@id)
end
|
#undefined? ⇒ Boolean
341
342
343
|
# File 'lib/bitclust/methodentry.rb', line 341
def undefined?
kind() == :undefined
end
|
#until_map ⇒ Object
232
233
234
|
# File 'lib/bitclust/methodentry.rb', line 232
def until_map
decode_version_tokens(until_by_name)
end
|
#until_of(name) ⇒ Object
224
225
226
|
# File 'lib/bitclust/methodentry.rb', line 224
def until_of(name)
until_map[name]
end
|