Class: YARD::RegistryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/registry_store.rb

Overview

The data store for the Registry.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RegistryStore) initialize



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yard/registry_store.rb', line 13

def initialize
  @file = nil
  @checksums = {}
  @store = {}
  @proxy_types = {}
  @object_types = {:root => [:root]}
  @notfound = {}
  @loaded_objects = 0
  @available_objects = 0
  @locales = {}
  @store[:root] = CodeObjects::RootObject.allocate
  @store[:root].send(:initialize, nil, :root)
end

Instance Attribute Details

- (Object) checksums (readonly)

Returns the value of attribute checksums



11
12
13
# File 'lib/yard/registry_store.rb', line 11

def checksums
  @checksums
end

- (Object) file (readonly)

Returns the value of attribute file



11
12
13
# File 'lib/yard/registry_store.rb', line 11

def file
  @file
end

- (Object) proxy_types (readonly)

Deprecated.

The registry no longer tracks proxy types



10
11
12
# File 'lib/yard/registry_store.rb', line 10

def proxy_types
  @proxy_types
end

Instance Method Details

- (Object) checksums_path (protected)



225
226
227
# File 'lib/yard/registry_store.rb', line 225

def checksums_path
  @serializer.checksums_path
end

- (void) delete(key)

This method returns an undefined value.

Deletes an object at a given path



73
# File 'lib/yard/registry_store.rb', line 73

def delete(key) @store.delete(key.to_sym) end

- (Boolean) destroy(force = false)

Deletes the .yardoc database on disk



200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/yard/registry_store.rb', line 200

def destroy(force = false)
  if (!force && file =~ /\.yardoc$/) || force
    if File.file?(@file)
      # Handle silent upgrade of old .yardoc format
      File.unlink(@file)
    elsif File.directory?(@file)
      FileUtils.rm_rf(@file)
    end
    true
  else
    false
  end
end

- (CodeObjects::Base?) get(key) Also known as: []

Gets a CodeObjects::Base from the store



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/yard/registry_store.rb', line 32

def get(key)
  key = :root if key == ''
  key = key.to_sym
  return @store[key] if @store[key]
  return if @loaded_objects >= @available_objects

  # check disk
  return if @notfound[key]
  if obj = @serializer.deserialize(key)
    @loaded_objects += 1
    put(key, obj)
  else
    @notfound[key] = true
    nil
  end
end

- (Array<Symbol>) keys(reload = false)

Gets all path names from the store. Loads the entire database if reload is true



81
# File 'lib/yard/registry_store.rb', line 81

def keys(reload = false) load_all if reload; @store.keys end

- (Boolean) load(file = nil)



121
122
123
124
125
126
127
128
129
# File 'lib/yard/registry_store.rb', line 121

def load(file = nil)
  @file = file
  @store = {}
  @proxy_types = {}
  @object_types = {}
  @notfound = {}
  @serializer = Serializers::YardocSerializer.new(@file)
  load_yardoc
end

- (Boolean) load!(file = nil)

Loads the .yardoc file and loads all cached objects into memory automatically.

See Also:

Since:

  • 0.5.1



138
139
140
141
142
143
144
145
# File 'lib/yard/registry_store.rb', line 138

def load!(file = nil)
  if load(file)
    load_all
    true
  else
    false
  end
end

- (void) load_all

This method returns an undefined value.

Loads all cached objects into memory



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/yard/registry_store.rb', line 149

def load_all
  return unless @file
  return if @loaded_objects >= @available_objects
  log.debug "Loading entire database: #{@file} ..."
  objects = []

  all_disk_objects.sort_by {|x| x.size }.each do |path|
    if obj = @serializer.deserialize(path, true)
      objects << obj
    end
  end
  objects.each do |obj|
    put(obj.path, obj)
  end
  @loaded_objects += objects.size
  log.debug "Loaded database (file='#{@file}' count=#{objects.size} total=#{@available_objects})"
end

- (Object) load_yardoc (protected)



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/yard/registry_store.rb', line 233

def load_yardoc
  return false unless @file
  if File.directory?(@file) # new format
    @loaded_objects = 0
    @available_objects = all_disk_objects.size
    load_proxy_types
    load_checksums
    load_root
    load_object_types
    true
  elsif File.file?(@file) # old format
    load_yardoc_old
    true
  else
    false
  end
end

- (I18n::Locale) locale(name)

Returns the locale object for name.

Since:

  • 0.8.3



115
116
117
# File 'lib/yard/registry_store.rb', line 115

def locale(name)
  @locales[name] ||= load_locale(name)
end

- (Object) object_types_path (protected)



229
230
231
# File 'lib/yard/registry_store.rb', line 229

def object_types_path
  @serializer.object_types_path
end

- (Object) objects_path (protected)



216
217
218
# File 'lib/yard/registry_store.rb', line 216

def objects_path
  @serializer.objects_path
end

- (Array<String>) paths_for_type(type, reload = false)

Returns a list of object paths with a given CodeObjects::Base#type

Since:

  • 0.8.0



95
96
97
98
# File 'lib/yard/registry_store.rb', line 95

def paths_for_type(type, reload = false)
  load_all if reload
  @object_types[type] || []
end

- (Object) proxy_types_path (protected)

Deprecated.

The registry no longer tracks proxy types



221
222
223
# File 'lib/yard/registry_store.rb', line 221

def proxy_types_path
  @serializer.proxy_types_path
end

- (CodeObjects::Base) put(key, value) Also known as: []=

Associates an object with a path



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/yard/registry_store.rb', line 53

def put(key, value)
  if key == ''
    @object_types[:root] = [:root]
    @store[:root] = value
  else
    @notfound.delete(key.to_sym)
    (@object_types[value.type] ||= []) << key.to_s
    if @store[key.to_sym]
      @object_types[@store[key.to_sym].type].delete(key.to_s)
    end
    @store[key.to_sym] = value
  end
end

- (CodeObjects::RootObject) root



110
# File 'lib/yard/registry_store.rb', line 110

def root; @store[:root] end

- (Boolean) save(merge = true, file = nil)

Saves the database to disk



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/yard/registry_store.rb', line 172

def save(merge = true, file = nil)
  if file && file != @file
    @file = file
    @serializer = Serializers::YardocSerializer.new(@file)
  end
  destroy unless merge

  sdb = Registry.single_object_db
  if sdb == true || sdb == nil
    @serializer.serialize(@store)
  else
    values(false).each do |object|
      @serializer.serialize(object)
    end
  end
  write_proxy_types
  write_object_types
  write_checksums
  true
end

- (Array<CodeObjects::Base>) values(reload = false)

Gets all code objects from the store. Loads the entire database if reload is true



89
# File 'lib/yard/registry_store.rb', line 89

def values(reload = false) load_all if reload; @store.values end

- (Array<CodeObjects::Base>) values_for_type(type, reload = false)

Returns a list of objects with a given CodeObjects::Base#type

Since:

  • 0.8.0



104
105
106
107
# File 'lib/yard/registry_store.rb', line 104

def values_for_type(type, reload = false)
  load_all if reload
  paths_for_type(type).map {|t| @store[t.to_sym] }
end