adjust API

This commit is contained in:
Sam 2017-02-14 16:32:33 -05:00
parent 89d5e8ab4b
commit f2099c3811
2 changed files with 4 additions and 4 deletions

View File

@ -6,11 +6,11 @@ class TopicList
cattr_accessor :preloaded_custom_fields cattr_accessor :preloaded_custom_fields
self.preloaded_custom_fields = Set.new self.preloaded_custom_fields = Set.new
def self.on_preload(blk) def self.on_preload(&blk)
(@preload ||= Set.new) << blk (@preload ||= Set.new) << blk
end end
def self.cancel_preload(blk) def self.cancel_preload(&blk)
if @preload if @preload
@preload.delete blk @preload.delete blk
if @preload.length == 0 if @preload.length == 0

View File

@ -36,12 +36,12 @@ describe TopicList do
preloaded_topic = true preloaded_topic = true
end end
TopicList.on_preload(preloader) TopicList.on_preload(&preloader)
topic_list.topics topic_list.topics
expect(preloaded_topic).to eq(true) expect(preloaded_topic).to eq(true)
TopicList.cancel_preload(preloader) TopicList.cancel_preload(&preloader)
end end
end end