Class: BitClust::LibraryEntry

Inherits:
Entry show all
Includes:
Enumerable
Defined in:
lib/bitclust/libraryentry.rb

Overview

Entry for libraries (“_builtin”, “yaml”, etc.)

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, #save, #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) ⇒ LibraryEntry

Returns a new instance of LibraryEntry.


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bitclust/libraryentry.rb', line 24

def initialize(db, id)
  super db
  @id = id
  @name = libid2name(@id)
  if saved?
    @classmap = nil
    @methodmap = nil
    @link_checked = true
  else
    @classmap = {}
    @methodmap = {}
    @link_checked = false
  end
  init_properties
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id


40
41
42
# File 'lib/bitclust/libraryentry.rb', line 40

def id
  @id
end

#nameObject (readonly) Also known as: label

Returns the value of attribute name


40
41
42
# File 'lib/bitclust/libraryentry.rb', line 40

def name
  @name
end

Class Method Details

.type_idObject


20
21
22
# File 'lib/bitclust/libraryentry.rb', line 20

def LibraryEntry.type_id
  :library
end

Instance Method Details

#<=>(other) ⇒ Object


54
55
56
# File 'lib/bitclust/libraryentry.rb', line 54

def <=>(other)
  @id.casecmp(other.id)
end

#==(other) ⇒ Object Also known as: eql?


44
45
46
# File 'lib/bitclust/libraryentry.rb', line 44

def ==(other)
  @id == other.id
end

#add_class(c) ⇒ Object


201
202
203
204
205
206
207
# File 'lib/bitclust/libraryentry.rb', line 201

def add_class(c)
  unless classmap()[c.name]
    classes().push c
    classmap()[c.name] = c
    @db.dirty_library self
  end
end

#add_method(m) ⇒ Object


209
210
211
212
213
214
215
# File 'lib/bitclust/libraryentry.rb', line 209

def add_method(m)
  unless methodmap()[m]
    methods().push m
    methodmap()[m] = m
    @db.dirty_library self
  end
end

#all_classesObject


102
103
104
105
106
# File 'lib/bitclust/libraryentry.rb', line 102

def all_classes
  return @all_classes if @all_classes
  required_classes = (sublibraries & requires).map{|l| l.classes }.flatten
  @all_classes = (classes() + required_classes).uniq.sort
end

#all_error_classesObject


112
113
114
# File 'lib/bitclust/libraryentry.rb', line 112

def all_error_classes
  @all_error_classes ||= all_classes.select{|c| c.error_class? }
end

#all_modulesObject


116
117
118
# File 'lib/bitclust/libraryentry.rb', line 116

def all_modules
  @all_modules ||= all_classes.select{|c| c.module? }.sort
end

#all_objectsObject


120
121
122
# File 'lib/bitclust/libraryentry.rb', line 120

def all_objects
  @all_objects ||= all_classes.select{|c| c.object? }.sort
end

#all_requires(libs = {}) ⇒ Object


93
94
95
96
97
98
99
100
# File 'lib/bitclust/libraryentry.rb', line 93

def all_requires(libs = {})
  requires.each{|l|
    next if libs[l.name]
    libs[l.name] = l
    l.all_requires(libs)
  }
  libs.values
end

80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bitclust/libraryentry.rb', line 80

def check_link(path = [])
  return if @link_checked
  if path.include?(name())
    raise InvalidLink, "looped require: #{path_string(path)}"
  end
  path.push name()
  requires().each do |lib|
    lib.check_link path
  end
  path.pop
  @link_checked = true
end

#classnamesObject


144
145
146
# File 'lib/bitclust/libraryentry.rb', line 144

def classnames
  classes().map {|c| c.name }
end

#each_class(&block) ⇒ Object


148
149
150
# File 'lib/bitclust/libraryentry.rb', line 148

def each_class(&block)
  classes().each(&block)
end

#each_method(&block) ⇒ Object


185
186
187
# File 'lib/bitclust/libraryentry.rb', line 185

def each_method(&block)
  methods().each(&block)
end

#error_classesObject


108
109
110
# File 'lib/bitclust/libraryentry.rb', line 108

def error_classes
  @error_classes ||= classes.select{|c| c.error_class? }
end

#fetch_class(name) ⇒ Object


135
136
137
138
# File 'lib/bitclust/libraryentry.rb', line 135

def fetch_class(name)
  get_class(name) or
      raise ClassNotFound, "no such class in the library #{name()}: #{name}"
end

#fetch_method(spec) ⇒ Object


176
177
178
179
180
181
182
183
# File 'lib/bitclust/libraryentry.rb', line 176

def fetch_method(spec)
  classes().each do |c|
    m = c.get_method(spec)
    return m if m
  end
  methods().detect {|m| spec.match?(m) } or
    raise MethodNotFound, "no such method in the library #{name()}: #{name}"
end

#fetch_methods(spec) ⇒ Object


164
165
166
167
168
169
170
171
172
173
174
# File 'lib/bitclust/libraryentry.rb', line 164

def fetch_methods(spec)
  ms = if c = get_class(spec.klass)
       then c.fetch_methods(spec)
       else []
       end +
       methods().select {|m| spec.match?(m) }
  if ms.empty?
    raise MethodNotFound, "no such method in the library #{name()}: #{name}"
  end
  ms
end

#get_class(name) ⇒ Object


140
141
142
# File 'lib/bitclust/libraryentry.rb', line 140

def get_class(name)
  classes().detect {|c| c.name == name }
end

#hashObject


50
51
52
# File 'lib/bitclust/libraryentry.rb', line 50

def hash
  @id.hash
end

#inspectObject


76
77
78
# File 'lib/bitclust/libraryentry.rb', line 76

def inspect
  "#<library #{@id}>"
end

#labelsObject


58
59
60
# File 'lib/bitclust/libraryentry.rb', line 58

def labels
  [label()]
end

#name?(n) ⇒ Boolean

Returns:

  • (Boolean)

62
63
64
# File 'lib/bitclust/libraryentry.rb', line 62

def name?(n)
  name() == n
end

#require(lib) ⇒ Object


124
125
126
# File 'lib/bitclust/libraryentry.rb', line 124

def require(lib)
  requires().push lib
end

#sublibrary(lib) ⇒ Object


128
129
130
131
132
133
# File 'lib/bitclust/libraryentry.rb', line 128

def sublibrary(lib)
  unless sublibraries().include?(lib)
    sublibraries().push lib
    lib.is_sublibrary = true
  end
end