Skip to content

Commit 4b5c875

Browse files
authored
Merge pull request #1284 from tomoasleep/fix-registry-store-delete
Make sure deleted object's entries are removed from object_types
2 parents 890d4ad + 3a4c122 commit 4b5c875

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/yard/registry_store.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ def put(key, value)
7272
# Deletes an object at a given path
7373
# @param [#to_sym] key the key to delete
7474
# @return [void]
75-
def delete(key) @store.delete(key.to_sym) end
75+
def delete(key)
76+
if @store[key.to_sym]
77+
@object_types[@store[key.to_sym].type].delete(key.to_s)
78+
@store.delete(key.to_sym)
79+
end
80+
end
7681

7782
# Gets all path names from the store. Loads the entire database
7883
# if +reload+ is +true+

spec/registry_store_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ def saves_to_multidb
304304
end
305305
end
306306

307+
describe "#delete" do
308+
it "deletes the given object from store" do
309+
@store.put(:YARD, @foo)
310+
expect(@store.get(:YARD)).to be @foo
311+
expect(@store.paths_for_type(:method)).to eq ["YARD"]
312+
@store.delete(:YARD)
313+
expect(@store.get(:YARD)).to be nil
314+
expect(@store.paths_for_type(:method)).to eq []
315+
end
316+
end
317+
307318
describe "#locale" do
308319
it "loads ./po/LOCALE_NAME.po" do
309320
fr_locale = I18n::Locale.new("fr")

0 commit comments

Comments
 (0)