Parent

RDoc::RI::Store

A set of ri data.

The store manages reading and writing ri data for a project (gem, path, etc.) and maintains a cache of methods, classes and ancestors in the store.

Attributes

path[RW]

Path this store reads or writes

type[RW]

Type of ri datastore this was loaded from. See RDoc::RI::Driver, RDoc::RI::Paths.

cache[R]

Public Class Methods

new(path, type = nil) click to toggle source

Creates a new Store of type that will load or save to path

    # File lib/rdoc/ri/store.rb, line 29
29:   def initialize path, type = nil
30:     @type = type
31:     @path = path
32: 
33:     @cache = {
34:       :class_methods    => {},
35:       :instance_methods => {},
36:       :attributes       => {},
37:       :modules          => [],
38:       :ancestors        => {},
39:     }
40:   end

Public Instance Methods

ancestors() click to toggle source

Ancestors cache accessor. Maps a klass name to an Array of its ancestors in this store. If Foo in this store inherits from Object, Kernel won’t be listed (it will be included from ruby’s ri store).

    # File lib/rdoc/ri/store.rb, line 47
47:   def ancestors
48:     @cache[:ancestors]
49:   end
attributes() click to toggle source

Attributes cache accessor. Maps a class to an Array of its attributes.

    # File lib/rdoc/ri/store.rb, line 54
54:   def attributes
55:     @cache[:attributes]
56:   end
cache_path() click to toggle source

Path to the cache file

    # File lib/rdoc/ri/store.rb, line 61
61:   def cache_path
62:     File.join @path, 'cache.ri'
63:   end
class_file(klass_name) click to toggle source

Path to the ri data for klass_name

    # File lib/rdoc/ri/store.rb, line 68
68:   def class_file klass_name
69:     name = klass_name.split('::').last
70:     File.join class_path(klass_name), "cdesc-#{name}.ri"
71:   end
class_methods() click to toggle source

Class methods cache accessor. Maps a class to an Array of its class methods (not full name).

    # File lib/rdoc/ri/store.rb, line 77
77:   def class_methods
78:     @cache[:class_methods]
79:   end
class_path(klass_name) click to toggle source

Path where data for klass_name will be stored (methods or class data)

    # File lib/rdoc/ri/store.rb, line 84
84:   def class_path klass_name
85:     File.join @path, *klass_name.split('::')
86:   end
friendly_path() click to toggle source

Friendly rendition of path

     # File lib/rdoc/ri/store.rb, line 91
 91:   def friendly_path
 92:     case type
 93:     when :gem    then
 94:       sep = Regexp.union(*['/', File::ALT_SEPARATOR].compact)
 95:       @path =~ /#{sep}doc#{sep}(.*?)#{sep}ri$/
 96:       "gem #{$1}"
 97:     when :home   then '~/.ri'
 98:     when :site   then 'ruby site'
 99:     when :system then 'ruby core'
100:     else @path
101:     end
102:   end
instance_methods() click to toggle source

Instance methods cache accessor. Maps a class to an Array of its instance methods (not full name).

     # File lib/rdoc/ri/store.rb, line 112
112:   def instance_methods
113:     @cache[:instance_methods]
114:   end
load_cache() click to toggle source

Loads cache file for this store

     # File lib/rdoc/ri/store.rb, line 119
119:   def load_cache
120:     open cache_path, 'rb' do |io|
121:       @cache = Marshal.load io.read
122:     end
123:   rescue Errno::ENOENT
124:   end
load_class(klass_name) click to toggle source

Loads ri data for klass_name

     # File lib/rdoc/ri/store.rb, line 129
129:   def load_class klass_name
130:     open class_file(klass_name), 'rb' do |io|
131:       Marshal.load io.read
132:     end
133:   end
load_method(klass_name, method_name) click to toggle source

Loads ri data for method_name in klass_name

     # File lib/rdoc/ri/store.rb, line 138
138:   def load_method klass_name, method_name
139:     open method_file(klass_name, method_name), 'rb' do |io|
140:       Marshal.load io.read
141:     end
142:   end
method_file(klass_name, method_name) click to toggle source

Path to the ri data for method_name in klass_name

     # File lib/rdoc/ri/store.rb, line 147
147:   def method_file klass_name, method_name
148:     method_name = method_name.split('::').last
149:     method_name =~ /#(.*)/
150:     method_type = $1 ? 'i' : 'c'
151:     method_name = $1 if $1
152: 
153:     method_name = if ''.respond_to? :ord then
154:                     method_name.gsub(/\W/) { "%%%02x" % $&[0].ord }
155:                   else
156:                     method_name.gsub(/\W/) { "%%%02x" % $&[0] }
157:                   end
158: 
159:     File.join class_path(klass_name), "#{method_name}-#{method_type}.ri"
160:   end
modules() click to toggle source

Modules cache accessor. An Array of all the modules (and classes) in the store.

     # File lib/rdoc/ri/store.rb, line 166
166:   def modules
167:     @cache[:modules]
168:   end
save_cache() click to toggle source

Writes the cache file for this store

     # File lib/rdoc/ri/store.rb, line 173
173:   def save_cache
174:     # HACK mongrel-1.1.5 documents its files twice
175:     @cache[:attributes].      each do |_, m| m.uniq!; m.sort! end
176:     @cache[:class_methods].   each do |_, m| m.uniq!; m.sort! end
177:     @cache[:instance_methods].each do |_, m| m.uniq!; m.sort! end
178: 
179:     open cache_path, 'wb' do |io|
180:       Marshal.dump @cache, io
181:     end
182:   end
save_class(klass) click to toggle source

Writes the ri data for klass

     # File lib/rdoc/ri/store.rb, line 187
187:   def save_class klass
188:     FileUtils.mkdir_p class_path(klass.full_name)
189: 
190:     @cache[:modules] << klass.full_name
191: 
192:     path = class_file klass.full_name
193: 
194:     begin
195:       disk_klass = nil
196: 
197:       open path, 'rb' do |io|
198:         disk_klass = Marshal.load io.read
199:       end
200: 
201:       klass.merge disk_klass
202:     rescue Errno::ENOENT
203:     end
204: 
205:     # BasicObject has no ancestors
206:     ancestors = klass.ancestors.compact.map do |ancestor|
207:       # HACK for classes we don't know about (class X < RuntimeError)
208:       String === ancestor ? ancestor : ancestor.full_name
209:     end
210: 
211:     @cache[:ancestors][klass.full_name] ||= []
212:     @cache[:ancestors][klass.full_name].push(*ancestors)
213: 
214:     attributes = klass.attributes.map do |attribute|
215:       "#{attribute.type} #{attribute.name}"
216:     end
217: 
218:     unless attributes.empty? then
219:       @cache[:attributes][klass.full_name] ||= []
220:       @cache[:attributes][klass.full_name].push(*attributes)
221:     end
222: 
223:     open path, 'wb' do |io|
224:       Marshal.dump klass, io
225:     end
226:   end
save_method(klass, method) click to toggle source

Writes the ri data for method on klass

     # File lib/rdoc/ri/store.rb, line 231
231:   def save_method klass, method
232:     FileUtils.mkdir_p class_path(klass.full_name)
233: 
234:     cache = if method.singleton then
235:               @cache[:class_methods]
236:             else
237:               @cache[:instance_methods]
238:             end
239:     cache[klass.full_name] ||= []
240:     cache[klass.full_name] << method.name
241: 
242:     open method_file(klass.full_name, method.full_name), 'wb' do |io|
243:       Marshal.dump method, io
244:     end
245:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.