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.



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

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.



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

def class
  @class
end

#instance_methodsObject (readonly)

Returns the value of attribute instance_methods.



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

def instance_methods
  @instance_methods
end

#singleton_methodsObject (readonly)

Returns the value of attribute singleton_methods.



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

def singleton_methods
  @singleton_methods
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

Class Method Details

.open(dir, version) ⇒ Object



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

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

.open_system_dbObject



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

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

Instance Method Details

#current_class=(name) ⇒ Object



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

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



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

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

#lookup_class(name) ⇒ Object



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

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