]> git.cworth.org Git - sup/blobdiff - lib/sup/source.rb
have mbox, maildir and imap sources (de)serialize labels nicely
[sup] / lib / sup / source.rb
index fb9089fc37dab718eaead5d0aaab65c0a4b3d41d..0705a75498607d192223fb1f2a3abc4ad960b5c3 100644 (file)
@@ -161,6 +161,21 @@ protected
   end
 end
 
+## if you have a @labels instance variable, include this
+## to serialize them nicely as an array, rather than as a
+## nasty set.
+module SerializeLabelsNicely
+  def before_marshal # can return an object
+    c = clone
+    c.instance_eval { @labels = @labels.to_a.map { |l| l.to_s } }
+    c
+  end
+
+  def after_unmarshal!
+    @labels = Set.new(@labels.map { |s| s.to_sym })
+  end
+end
+
 class SourceManager
   include Singleton