Class: RiDatabase

Inherits:
Object show all
Defined in:
lib/bitclust/ridatabase.rb

Overview

Handle RDoc(ri) database for tools/bc-rdoc.rb and `bitclust methods –diff`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ripath, version) ⇒ RiDatabase

Returns a new instance of RiDatabase.


19
20
21
22
23
# File 'lib/bitclust/ridatabase.rb', line 19

def initialize(ripath, version)
  @ripath = ripath
  @reader = RI::RiReader.new(RI::RiCache.new(@ripath))
  @version = version
end

Instance Attribute Details

#classObject (readonly)

Returns the value of attribute class


41
42
43
# File 'lib/bitclust/ridatabase.rb', line 41

def class
  @class
end

#instance_methodsObject (readonly)

Returns the value of attribute instance_methods


43
44
45
# File 'lib/bitclust/ridatabase.rb', line 43

def instance_methods
  @instance_methods
end

#singleton_methodsObject (readonly)

Returns the value of attribute singleton_methods


42
43
44
# File 'lib/bitclust/ridatabase.rb', line 42

def singleton_methods
  @singleton_methods
end

#versionObject (readonly)

Returns the value of attribute version


25
26
27
# File 'lib/bitclust/ridatabase.rb', line 25

def version
  @version
end

Class Method Details

.open(dir, version) ⇒ Object


15
16
17
# File 'lib/bitclust/ridatabase.rb', line 15

def RiDatabase.open(dir, version)
  new(RI::Paths.path(false, false, false, false, dir), version)
end

.open_system_dbObject


11
12
13
# File 'lib/bitclust/ridatabase.rb', line 11

def RiDatabase.open_system_db
  new(RI::Paths.path(true, false, false, false), RUBY_VERSION)
end

Instance Method Details

#current_class=(name) ⇒ Object


31
32
33
34
35
36
37
38
39
# File 'lib/bitclust/ridatabase.rb', line 31

def current_class=(name)
  @klass = lookup_class(name)
  @singleton_methods = wrap_entries(@reader.singleton_methods(@klass))
  @instance_methods = wrap_entries(@reader.instance_methods(@klass))
rescue RiClassNotFound
  @klass = nil
  @singleton_methods = []
  @instance_methods = []
end

#get_method(m) ⇒ Object


27
28
29
# File 'lib/bitclust/ridatabase.rb', line 27

def get_method(m)
  @reader.get_method(m)
end

#lookup_class(name) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/bitclust/ridatabase.rb', line 45

def lookup_class(name)
  ns = @reader.top_level_namespace.first
  name.split('::').each do |const|
    ns = ns.contained_class_named(const) or
        raise RiClassNotFound, "no such class in RDoc database: #{name}"
  end
  ns
end