commit 70bcc4ed051c389e82b76dc6f57e5f009aac1e83
parent 4e496c5bd66de3d916795901ecdbb52e6f1cee84
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Wed, 19 Aug 2009 14:32:46 -0400
have mbox, maildir and imap sources (de)serialize labels nicely
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.
Diffstat:
4 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb
@@ -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
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
@@ -9,6 +9,7 @@ module Redwood
## pathnames on disk.
class Maildir < Source
+ include SerializeLabelsNicely
SCAN_INTERVAL = 30 # seconds
MYHOSTNAME = Socket.gethostname
diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb
@@ -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.
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -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