lib/picky/bundle_realtime.rb in picky-3.4.3 vs lib/picky/bundle_realtime.rb in picky-3.5.0

- old
+ new

@@ -30,26 +30,28 @@ @realtime_mapping.delete id end # Returns a reference to the array where the id has been added. # - def add id, sym + # TODO Rename sym. + # + def add id, sym, where = :unshift ary = @inverted[sym] syms = @realtime_mapping[id] syms = (@realtime_mapping[id] = []) unless syms # TODO Nicefy. # Inverted. # ids = if syms.include? sym ids = @inverted[sym] - ids.delete id # Move id - ids.unshift id # to front + ids.delete id + ids.send where, id else syms << sym ids = @inverted[sym] ||= [] - ids.unshift id + ids.send where, id end # Weights. # @weights[sym] = self.weights_strategy.weight_for ids.size @@ -58,22 +60,28 @@ # if encoded = self.similarity_strategy.encoded(sym) similarity = @similarity[encoded] ||= [] if similarity.include? sym similarity.delete sym # Not completely correct, as others will also be affected, but meh. - similarity.unshift sym # + similarity.send where, sym # else - similarity.unshift sym + similarity.send where, sym end end end # Partializes the text and then adds each. # - def add_partialized id, text + def add_partialized id, text, where = :unshift self.partial_strategy.each_partial text do |partial_text| - add id, partial_text + add id, partial_text, where end + end + + # Clears the realtime mapping. + # + def clear_realtime_mapping + @realtime_mapping.clear end end end \ No newline at end of file