]> git.cworth.org Git - sup/commitdiff
have mbox, maildir and imap sources (de)serialize labels nicely
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 19 Aug 2009 18:32:46 +0000 (14:32 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 19 Aug 2009 18:32:46 +0000 (14:32 -0400)
At output time, rather than emitting a YAML Set (which is nasty), emit an array
of strings. At input time, normalize into a Set of labels.

lib/sup/imap.rb
lib/sup/maildir.rb
lib/sup/mbox/loader.rb
lib/sup/source.rb

index 14acdb775764655152a0062f3010dc7b9d38f7b9..b048ba9ea18f9a2e538b1df698db03169e25f0a8 100644 (file)
@@ -48,6 +48,7 @@ require 'set'
 module Redwood
 
 class IMAP < Source
+  include SerializeLabelsNicely
   SCAN_INTERVAL = 60 # seconds
 
   ## upon these errors we'll try to rereconnect a few times
index 80903e28ca6cd6231df0563dae4977c0aa5cfe34..db35dad0f52bab455eb47e2ef027eb63cf8d54b1 100644 (file)
@@ -9,6 +9,7 @@ module Redwood
 ## pathnames on disk.
 
 class Maildir < Source
+  include SerializeLabelsNicely
   SCAN_INTERVAL = 30 # seconds
   MYHOSTNAME = Socket.gethostname
 
index 26177f76bb12041c7cbfee16414f656a6dd15afc..030759483289f2ee6bd115b818e9dfecb5a986de 100644 (file)
@@ -6,6 +6,7 @@ module Redwood
 module MBox
 
 class Loader < Source
+  include SerializeLabelsNicely
   yaml_properties :uri, :cur_offset, :usual, :archived, :id, :labels
 
   ## uri_or_fp is horrific. need to refactor.
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