Class: YARD::RegistryStore
- Inherits:
-
Object
- Object
- YARD::RegistryStore
- Defined in:
- lib/yard/registry_store.rb
Overview
The data store for the Registry.
Instance Attribute Summary (collapse)
-
- (Object) checksums
readonly
Returns the value of attribute checksums.
-
- (Object) file
readonly
Returns the value of attribute file.
-
- (Object) proxy_types
readonly
Returns the value of attribute proxy_types.
Instance Method Summary (collapse)
- - (Object) checksums_path protected
- - (Object) delete(key)
-
- (Boolean) destroy(force = false)
Deletes the .yardoc database on disk.
-
- (CodeObjects::Base?) get(key)
(also: #[])
Gets a CodeObjects::Base from the store.
-
- (RegistryStore) initialize
constructor
A new instance of RegistryStore.
-
- (Array<Symbol>) keys(reload = false)
Gets all path names from the store.
-
- (Boolean) load(file = nil)
Whether the database was loaded.
-
- (Boolean) load!(file = nil)
Loads the .yardoc file and loads all cached objects into memory automatically.
-
- (void) load_all
Loads all cached objects into memory.
- - (Object) load_yardoc protected
- - (Object) objects_path protected
- - (Object) proxy_types_path protected
-
- (CodeObjects::Base) put(key, value)
(also: #[]=)
Associates an object with a path.
-
- (CodeObjects::RootObject) root
The root object.
-
- (Boolean) save(merge = true, file = nil)
Saves the database to disk.
-
- (Array<CodeObjects::Base>) values(reload = false)
Gets all code objects from the store.
Constructor Details
- (RegistryStore) initialize
A new instance of RegistryStore
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yard/registry_store.rb', line 11 def initialize @file = nil @checksums = {} @store = {} @proxy_types = {} @notfound = {} @loaded_objects = 0 @available_objects = 0 @store[:root] = CodeObjects::RootObject.allocate @store[:root].send(:initialize, nil, :root) end |
Instance Attribute Details
- (Object) checksums (readonly)
Returns the value of attribute checksums
9 10 11 |
# File 'lib/yard/registry_store.rb', line 9 def checksums @checksums end |
- (Object) file (readonly)
Returns the value of attribute file
9 10 11 |
# File 'lib/yard/registry_store.rb', line 9 def file @file end |
- (Object) proxy_types (readonly)
Returns the value of attribute proxy_types
9 10 11 |
# File 'lib/yard/registry_store.rb', line 9 def proxy_types @proxy_types end |
Instance Method Details
- (Object) checksums_path (protected)
185 186 187 |
# File 'lib/yard/registry_store.rb', line 185 def checksums_path @serializer.checksums_path end |
- (Object) delete(key)
61 |
# File 'lib/yard/registry_store.rb', line 61 def delete(key) @store.delete(key.to_sym) end |
- (Boolean) destroy(force = false)
Deletes the .yardoc database on disk
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/yard/registry_store.rb', line 161 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/yard/registry_store.rb', line 28 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
69 |
# File 'lib/yard/registry_store.rb', line 69 def keys(reload = false) load_all if reload; @store.keys end |
- (Boolean) load(file = nil)
Whether the database was loaded
84 85 86 87 88 89 90 91 |
# File 'lib/yard/registry_store.rb', line 84 def load(file = nil) @file = file @store = {} @proxy_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.
100 101 102 103 104 105 106 107 |
# File 'lib/yard/registry_store.rb', line 100 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
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/yard/registry_store.rb', line 111 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)
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/yard/registry_store.rb', line 189 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 true elsif File.file?(@file) # old format load_yardoc_old true else false end end |
- (Object) objects_path (protected)
177 178 179 |
# File 'lib/yard/registry_store.rb', line 177 def objects_path @serializer.objects_path end |
- (Object) proxy_types_path (protected)
181 182 183 |
# File 'lib/yard/registry_store.rb', line 181 def proxy_types_path @serializer.proxy_types_path end |
- (CodeObjects::Base) put(key, value) Also known as: []=
Associates an object with a path
49 50 51 52 53 54 55 56 |
# File 'lib/yard/registry_store.rb', line 49 def put(key, value) if key == '' @store[:root] = value else @notfound.delete(key.to_sym) @store[key.to_sym] = value end end |
- (CodeObjects::RootObject) root
The root object
80 |
# File 'lib/yard/registry_store.rb', line 80 def root; @store[:root] end |
- (Boolean) save(merge = true, file = nil)
Saves the database to disk
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/yard/registry_store.rb', line 134 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 && keys.size < 3000) @serializer.serialize(@store) else values(false).each do |object| @serializer.serialize(object) end end write_proxy_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
77 |
# File 'lib/yard/registry_store.rb', line 77 def values(reload = false) load_all if reload; @store.values end |