commit bdd169b5d6c8fad37a2714bb29a95fd0a66ce709
parent fa0b5a25587356684bd45b82b172fedc729038d5
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Tue, 26 May 2009 14:43:07 -0700
Merge branch 'master' into next
Diffstat:
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -13,8 +13,8 @@ class MessageFormatError < StandardError; end
## specific module that would detect and link to /ruby-talk:\d+/
## sequences in the text of an email. (how sweet would that be?)
##
-## this class cathces all source exceptions. if the underlying source throws
-## an error, it is caught and handled.
+## this class catches all source exceptions. if the underlying source
+## throws an error, it is caught and handled.
class Message
SNIPPET_LEN = 80
@@ -50,7 +50,7 @@ class Message
@snippet = opts[:snippet]
@snippet_contains_encrypted_content = false
@have_snippet = !(opts[:snippet].nil? || opts[:snippet].empty?)
- @labels = [] + (opts[:labels] || [])
+ @labels = (opts[:labels] || []).to_set_of_symbols
@dirty = false
@encrypted = false
@chunks = nil
@@ -164,7 +164,7 @@ class Message
def has_label? t; @labels.member? t; end
def add_label t
return if @labels.member? t
- @labels.push t
+ @labels = (@labels + [t]).to_set_of_symbols
@dirty = true
end
def remove_label t
@@ -178,7 +178,7 @@ class Message
end
def labels= l
- @labels = l
+ @labels = l.to_set_of_symbols
@dirty = true
end
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -405,6 +405,10 @@ class Array
def last= e; self[-1] = e end
def nonempty?; !empty? end
+
+ def to_set_of_symbols
+ map { |x| x.is_a?(Symbol) ? x : x.intern }.uniq
+ end
end
class Time