module Fiona7 module WidgetGc module SweepStrategies # This garbage collection strategy deletes working versions # of garbage widget objects # Its usefulness is limited to objects which hasn't been released yet # or gained links in working version # # This strategy should be only used # after deleting widgets class RevertSweep def initialize(object, widget_resolver) self.object = object self.widget_resolver = widget_resolver end def sweep!(garbage) garbage.each do |widget_object_id| # TODO: improve performance here widget_object = self.widget_resolver.all.find {|w| w.id == widget_object_id } revert!(widget_object) end end protected attr_accessor :object, :widget_resolver def revert!(widget_object) widget_object.take! if widget_object.really_edited? widget_object.revert! if widget_object.really_edited? end end end end end