Class: YARD::RegistryStore
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/yard/registry_store.rb |
Overview
The data store for the Registry
.
Class Method Summary
- .new ⇒ RegistryStore constructor
Instance Attribute Summary
- #checksums readonly
- #file readonly
-
#proxy_types
readonly
deprecated
Deprecated.
The registry no longer tracks proxy types
Instance Method Summary
-
#[](key)
Alias for #get.
-
#[]=(key, value)
Alias for #put.
-
#delete(key) ⇒ void
Deletes an object at a given path.
-
#destroy(force = false) ⇒ Boolean
Deletes the .yardoc database on disk.
-
#get(key) ⇒ CodeObjects::Base?
(also: #[])
Gets a
CodeObjects::Base
from the store. -
#keys(reload = false) ⇒ Array<Symbol>
Gets all path names from the store.
- #load(file = nil) ⇒ Boolean
-
#load!(file = nil) ⇒ Boolean
Loads the .yardoc file and loads all cached objects into memory automatically.
-
#load_all ⇒ void
Loads all cached objects into memory.
- #locale(name) ⇒ I18n::Locale
-
#lock_for_writing(file = nil, &block)
Creates a pessmistic transactional lock on the database for writing.
- #locked_for_writing?(file = nil) ⇒ Boolean
- #paths_for_type(type, reload = false) ⇒ Array<String>
-
#put(key, value) ⇒ CodeObjects::Base
(also: #[]=)
Associates an object with a path.
- #root ⇒ CodeObjects::RootObject
-
#save(merge = true, file = nil) ⇒ Boolean
Saves the database to disk.
-
#values(reload = false) ⇒ Array<CodeObjects::Base>
Gets all code objects from the store.
- #values_for_type(type, reload = false) ⇒ Array<CodeObjects::Base>
- #all_disk_objects private
- #load_checksums private
- #load_locale(name) private
- #load_object_types private
-
#load_proxy_types
private
deprecated
Deprecated.
The registry no longer tracks proxy types
- #load_root private
- #load_yardoc_old private
- #write_checksums private
- #write_complete_lock private
- #write_object_types private
-
#write_proxy_types
private
deprecated
Deprecated.
The registry no longer tracks proxy types
Constructor Details
.new ⇒ RegistryStore
# File 'lib/yard/registry_store.rb', line 14
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
#checksums (readonly)
[ GitHub ]# File 'lib/yard/registry_store.rb', line 12
attr_reader :file, :checksums
#file (readonly)
[ GitHub ]# File 'lib/yard/registry_store.rb', line 12
attr_reader :file, :checksums
#proxy_types (readonly)
The registry no longer tracks proxy types
# File 'lib/yard/registry_store.rb', line 11
attr_reader :proxy_types
Instance Method Details
#[](key)
Alias for #get.
# File 'lib/yard/registry_store.rb', line 69
alias [] get
#[]=(key, value)
Alias for #put.
# File 'lib/yard/registry_store.rb', line 70
alias []= put
#all_disk_objects (private)
[ GitHub ]
#delete(key) ⇒ void
This method returns an undefined value.
Deletes an object at a given path
# File 'lib/yard/registry_store.rb', line 75
def delete(key) if @store[key.to_sym] @object_types[@store[key.to_sym].type].delete(key.to_s) @store.delete(key.to_sym) end end
#destroy(force = false) ⇒ Boolean
Deletes the .yardoc database on disk
#get(key) ⇒ CodeObjects::Base? Also known as: #[]
Gets a CodeObjects::Base
from the store
# File 'lib/yard/registry_store.rb', line 33
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] obj = @serializer.deserialize(key) if obj @loaded_objects += 1 put(key, obj) else @notfound[key] = true nil end end
#keys(reload = false) ⇒ Array<Symbol
>
Gets all path names from the store. Loads the entire database
if reload
is true
# File 'lib/yard/registry_store.rb', line 88
def keys(reload = false) load_all if reload; @store.keys end
#load(file = nil) ⇒ Boolean
# File 'lib/yard/registry_store.rb', line 128
def load(file = nil) initialize @file = file @serializer = Serializers::YardocSerializer.new(@file) load_yardoc end
#load!(file = nil) ⇒ Boolean
Loads the .yardoc file and loads all cached objects into memory automatically.
#load_all ⇒ void
This method returns an undefined value.
Loads all cached objects into memory
# File 'lib/yard/registry_store.rb', line 153
def load_all return unless @file return if @loaded_objects >= @available_objects log.debug "Loading entire database: #{@file} ..." objects = [] all_disk_objects.sort_by(&:size).each do |path| obj = @serializer.deserialize(path, true) objects << obj if obj 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
#load_checksums (private)
[ GitHub ]#load_locale(name) (private)
[ GitHub ]#load_object_types (private)
[ GitHub ]# File 'lib/yard/registry_store.rb', line 281
def load_object_types if File.file?(object_types_path) @object_types = Marshal.load(File.read_binary(object_types_path)) else # migrate db without object_types values.each do |object| (@object_types[object.type] ||= []) << object.path end end end
#load_proxy_types (private)
The registry no longer tracks proxy types
# File 'lib/yard/registry_store.rb', line 276
def load_proxy_types return unless File.file?(proxy_types_path) @proxy_types = Marshal.load(File.read_binary(proxy_types_path)) end
#load_root (private)
[ GitHub ]# File 'lib/yard/registry_store.rb', line 299
def load_root root = @serializer.deserialize('root') return if root.nil? @loaded_objects += 1 if root.is_a?(Hash) # single object db log.debug "Loading single object DB from .yardoc" @loaded_objects += (root.keys.size - 1) @store = root else # just the root object @store[:root] = root end end
#load_yardoc_old (private)
[ GitHub ]# File 'lib/yard/registry_store.rb', line 271
def load_yardoc_old @store, @proxy_types = *Marshal.load(File.read_binary(@file)) end
#locale(name) ⇒ I18n::Locale
# File 'lib/yard/registry_store.rb', line 122
def locale(name) @locales[name] ||= load_locale(name) end
#lock_for_writing(file = nil, &block)
Creates a pessmistic transactional lock on the database for writing. Use with YARD.parse to ensure the database is not written multiple times.
# File 'lib/yard/registry_store.rb', line 201
def lock_for_writing(file = nil, &block) Serializers::YardocSerializer.new(file || @file).lock_for_writing(&block) end
#locked_for_writing?(file = nil) ⇒ Boolean
# File 'lib/yard/registry_store.rb', line 207
def locked_for_writing?(file = nil) Serializers::YardocSerializer.new(file || @file).locked_for_writing? end
#paths_for_type(type, reload = false) ⇒ Array<String>
# File 'lib/yard/registry_store.rb', line 102
def paths_for_type(type, reload = false) load_all if reload @object_types[type] || [] end
#put(key, value) ⇒ CodeObjects::Base Also known as: #[]=
Associates an object with a path
# File 'lib/yard/registry_store.rb', line 55
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
#root ⇒ CodeObjects::RootObject
#save(merge = true, file = nil) ⇒ Boolean
Saves the database to disk
# File 'lib/yard/registry_store.rb', line 177
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 write_complete_lock true end
#values(reload = false) ⇒ Array<CodeObjects::Base>
Gets all code objects from the store. Loads the entire database
if reload
is true
# File 'lib/yard/registry_store.rb', line 96
def values(reload = false) load_all if reload; @store.values end
#values_for_type(type, reload = false) ⇒ Array<CodeObjects::Base>
# File 'lib/yard/registry_store.rb', line 111
def values_for_type(type, reload = false) load_all if reload paths_for_type(type).map {|t| @store[t.to_sym] } end
#write_checksums (private)
[ GitHub ]#write_complete_lock (private)
[ GitHub ]#write_object_types (private)
[ GitHub ]#write_proxy_types (private)
The registry no longer tracks proxy types