Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] Message#edit_labels [was: [sup-talk] Ruby question: before-add-message.rb and adding multiple labels at once]
       [not found] <1263574849-sup-3477@sam.mediasupervision.de>
@ 2010-01-16 22:41 ` Tero Tilus
  2010-01-21 23:51   ` [sup-devel] [PATCH] Message#edit_labels [was: " Tero Tilus
  0 siblings, 1 reply; 5+ messages in thread
From: Tero Tilus @ 2010-01-16 22:41 UTC (permalink / raw)
  To: sup-talk; +Cc: Sup developers

Gregor Hoffleit, 2010-01-15 19:01:
> Ok. I ended up with
> 
>     ([:list,:"sup-devel"].each {|l| message.add_label l}; message.remove_label :inbox) if message.subj =~ /\[sup-devel\]/
> 
> May I request a new function "message.edit_labels" that groks the syntax
> of the 'edit labels' command (cf. multi_edit_labels in thread-index-mode.rb):
> 
>     message.edit_labels "list sup-devel -inbox" if message.subj =~ /\[sup-devel\]/
> 
> Comments?

I'll be using that one too.  Here's a patch.  Message#edit_labels
accepts array of strings.  I thought it'll be better that way.
Otherwise it gets really ugly with spaces in labels.

So your usecase would be

  message.edit_labels %w{list sup-devel -inbox} if message.subj =~ /\[sup-devel\]/

By the way, my pretty general list-labeling code looks like this
<http://pastie.org/781240>.

And then the patch...

From 9eff953dbda404b149a77969305c5732fa1d694e Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Sun, 17 Jan 2010 00:23:26 +0200
Subject: [PATCH] Message#edit_labels

Signed-off-by: Tero Tilus <tero@tilus.net>
---
 lib/sup/message.rb |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 3e55de5..e047927 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -206,6 +206,18 @@ class Message
     @labels.delete l
     @dirty = true
   end
+  ## calling m.edit_labels ['foo', '-index', '+bar']
+  ## adds labels foo and bar and removes label index
+  def edit_labels l_arr
+    l_arr.each do |signedlabel|
+      signedlabel, sign, label = signedlabel.match(/^(-|\+)?(.*)$/).to_a
+      if sign == '-'
+        remove_label label
+      else
+        add_label label
+      end
+    end
+  end
 
   def recipients
     @to + @cc + @bcc
-- 
1.5.6.5


-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Message#edit_labels [was: Ruby question: before-add-message.rb and adding multiple labels at once]
  2010-01-16 22:41 ` [sup-devel] [PATCH] Message#edit_labels [was: [sup-talk] Ruby question: before-add-message.rb and adding multiple labels at once] Tero Tilus
@ 2010-01-21 23:51   ` Tero Tilus
  2010-01-23 13:11     ` William Morgan
  0 siblings, 1 reply; 5+ messages in thread
From: Tero Tilus @ 2010-01-21 23:51 UTC (permalink / raw)
  To: Sup developers

Tero Tilus, 2010-01-17 00:41:
> Gregor Hoffleit, 2010-01-15 19:01:
>> May I request a new function "message.edit_labels"
> 
> I'll be using that one too.  Here's a patch.

Did this get merged?  I got no feedback.

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Message#edit_labels [was: Ruby question: before-add-message.rb and adding multiple labels at once]
  2010-01-21 23:51   ` [sup-devel] [PATCH] Message#edit_labels [was: " Tero Tilus
@ 2010-01-23 13:11     ` William Morgan
  2010-01-25  2:05       ` Tero Tilus
  0 siblings, 1 reply; 5+ messages in thread
From: William Morgan @ 2010-01-23 13:11 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from Tero Tilus's message of 2010-01-21:
> Did this get merged?  I got no feedback.

Sorry about that. This is very similar to the code in
ThreadViewMode#multi_edit_labels, so I would prefer a solution that
shared a codepath. It's also important to call LabelManager.<< for each
label, to make sure they appear in label-list-mode.
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Message#edit_labels [was: Ruby question: before-add-message.rb and adding multiple labels at once]
  2010-01-23 13:11     ` William Morgan
@ 2010-01-25  2:05       ` Tero Tilus
  2010-02-04  7:58         ` Tero Tilus
  0 siblings, 1 reply; 5+ messages in thread
From: Tero Tilus @ 2010-01-25  2:05 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 656 bytes --]

William Morgan, 2010-01-23 15:11:
> This is very similar to ThreadViewMode#multi_edit_labels, so I would
> prefer a solution that shared a codepath.

Similar indeed.  Factored out.

> It's also important to call LabelManager.<< for each label, to make
> sure they appear in label-list-mode.

I went a step further with this.  Counting on people not having
billion-mail threads and gazillions of tags (and thus this potentially
having performance implications) I dropped all the LabelManager.<<
calls to Message to ensure that every time labels change, LabelManager
is informed.

Patch v2 attached.

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/

[-- Attachment #2: 0001-Message-edit_labels.patch --]
[-- Type: application/octet-stream, Size: 7279 bytes --]

From 86fb100134747692e206fe007c0f886bdcff493e Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Mon, 25 Jan 2010 03:58:38 +0200
Subject: [PATCH] Message#edit_labels

 - updating labels using "diff" factored out to Message
 - pushing labels to LabelManager in Message (only) to ensure
   up-to-date label list in LabelManager

Signed-off-by: Tero Tilus <tero@tilus.net>
---
 lib/sup/message.rb                 |   17 +++++++++++++++++
 lib/sup/modes/thread-index-mode.rb |   19 ++-----------------
 lib/sup/modes/thread-view-mode.rb  |    1 -
 lib/sup/poll.rb                    |    1 -
 lib/sup/thread.rb                  |    7 ++++++-
 lib/sup/util.rb                    |   31 ++++++++++++++++++++++++++++---
 lib/sup/xapian_index.rb            |    1 -
 7 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 3e55de5..d2cdae0 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -48,6 +48,7 @@ class Message
     @snippet_contains_encrypted_content = false
     @have_snippet = !(opts[:snippet].nil? || opts[:snippet].empty?)
     @labels = Set.new(opts[:labels] || [])
+    @labels.each { |l| LabelManager << l }
     @dirty = false
     @encrypted = false
     @chunks = nil
@@ -198,6 +199,7 @@ class Message
     l = l.to_sym
     return if @labels.member? l
     @labels << l
+    LabelManager << l
     @dirty = true
   end
   def remove_label l
@@ -207,6 +209,20 @@ class Message
     @dirty = true
   end
 
+  ## Takes either a String or a Set of SignedSymbols.  Edits labels
+  ## accordingly.  Calling m.edit_labels 'foo -index +bar' adds labels
+  ## foo and bar and removes label index.
+  def edit_labels labels
+    labels = labels.to_ssym if labels.is_a? String
+    labels.each do |signedlabel|
+      if signedlabel.sign == :-
+        remove_label signedlabel.sym
+      else
+        add_label signedlabel.sym
+      end
+    end
+  end
+
   def recipients
     @to + @cc + @bcc
   end
@@ -215,6 +231,7 @@ class Message
     raise ArgumentError, "not a set" unless l.is_a?(Set)
     raise ArgumentError, "not a set of labels" unless l.all? { |ll| ll.is_a?(Symbol) }
     return if @labels == l
+    (l - @labels).each { |ll| LabelManager << ll }
     @labels = l
     @dirty = true
   end
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 28cb858..759e25f 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -527,7 +527,6 @@ EOS
     return unless user_labels
 
     thread.labels = Set.new(keepl) + user_labels
-    user_labels.each { |l| LabelManager << l }
     update_text_for_line curpos
 
     UndoManager.register "labeling thread" do
@@ -545,24 +544,11 @@ EOS
     user_labels = BufferManager.ask_for_labels :labels, "Add/remove labels (use -label to remove): ", [], @hidden_labels
     return unless user_labels
 
-    user_labels.map! { |l| (l.to_s =~ /^-/)? [l.to_s.gsub(/^-?/, '').to_sym, true] : [l, false] }
-    hl = user_labels.select { |(l,_)| @hidden_labels.member? l }
-    unless hl.empty?
-      BufferManager.flash "'#{hl}' is a reserved label!"
-      return
-    end
-
+    user_labels = user_labels.to_set_of_signed_symbols
     old_labels = threads.map { |t| t.labels.dup }
 
     threads.each do |t|
-      user_labels.each do |(l, to_remove)|
-        if to_remove
-          t.remove_label l
-        else
-          t.apply_label l
-          LabelManager << l
-        end
-      end
+      t.edit_labels user_labels
       UpdateManager.relay self, :labeled, t.first
     end
 
@@ -628,7 +614,6 @@ EOS
       ::Thread.pass
       break if @interrupt_search
     end
-    @ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }
 
     update
     BufferManager.clear @mbid
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index b08c819..682225b 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -273,7 +273,6 @@ EOS
 
     return unless new_labels
     @thread.labels = Set.new(reserved_labels) + new_labels
-    new_labels.each { |l| LabelManager << l }
     update
     UpdateManager.relay self, :labeled, @thread.first
     Index.save_thread @thread
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
index f3e1224..104bd70 100644
--- a/lib/sup/poll.rb
+++ b/lib/sup/poll.rb
@@ -163,7 +163,6 @@ EOS
         m = Message.build_from_source source, offset
         m.labels += source_labels + (source.archived? ? [] : [:inbox])
         m.labels.delete :unread if m.source_marked_read? # preserve read status if possible
-        m.labels.each { |l| LabelManager << l }
 
         HookManager.run "before-add-message", :message => m
         yield m
diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb
index 3fdf1f6..f159e5f 100644
--- a/lib/sup/thread.rb
+++ b/lib/sup/thread.rb
@@ -110,7 +110,6 @@ class Thread
     end
   end
 
-  def set_labels l; each { |m, *o| m && m.labels = l }; end
   def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end
   def each_dirty_message; each { |m, *o| m && m.dirty? && yield(m) }; end
 
@@ -130,6 +129,12 @@ class Thread
     each { |m, *o| m && m.labels = l.dup }
   end
 
+  ## see Message#edit_labels
+  def edit_labels labels
+    labels = labels.to_ssym if labels.is_a? String
+    each { |m, *o| m.edit_labels labels }
+  end
+
   def latest_message
     inject(nil) do |a, b|
       b = b.first
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index 866ba0d..bc4258b 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -296,12 +296,20 @@ class String
     end
   end
 
-  ## takes a list of words, and returns an array of symbols.  typically used in
+  ## Takes a list of words, and returns a set of given transforms.  Typically used in
   ## Sup for translating Ferret's representation of a list of labels (a string)
-  ## to an array of label symbols.
+  ## to an array of label symbols (see #to_set_of_symbols).
   ##
   ## split_on will be passed to String#split, so you can leave this nil for space.
-  def to_set_of_symbols split_on=nil; Set.new split(split_on).map { |x| x.strip.intern } end
+  def to_set_of mapping, split_on=nil; Set.new split(split_on).map { |x| x.strip.send mapping } end
+
+  def to_set_of_symbols split_on=nil; to_set_of :to_sym, split_on; end
+  def to_set_of_signed_symbols split_on=nil; to_set_of :to_ssym, split_on; end
+
+  def to_ssym
+    dummy, sign, label = self.match(/^(-|\+)?(.*)$/).to_a
+    SignedSymbol.new label.to_sym, ( sign=='-' ? :- : :+ )
+  end
 
   class CheckError < ArgumentError; end
   def check
@@ -331,6 +339,23 @@ class String
   end
 end
 
+class SignedSymbol
+  def initialize sym, sign
+    @sym = sym
+    @sign = sign
+  end
+  def sym; @sym; end
+  def sign; @sign; end
+end
+
+class Symbol
+  def to_ssym; to_s.to_ssym; end
+end
+
+class Set
+  def to_set_of_signed_symbols; map(&:to_ssym); end
+end
+
 class Numeric
   def clamp min, max
     if self < min
diff --git a/lib/sup/xapian_index.rb b/lib/sup/xapian_index.rb
index 0db5010..4a113d6 100644
--- a/lib/sup/xapian_index.rb
+++ b/lib/sup/xapian_index.rb
@@ -453,7 +453,6 @@ EOS
       @xapian.replace_document docid, doc
     end
 
-    m.labels.each { |l| LabelManager << l }
     true
   end
 
-- 
1.5.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [sup-devel] [PATCH] Message#edit_labels [was: Ruby question: before-add-message.rb and adding multiple labels at once]
  2010-01-25  2:05       ` Tero Tilus
@ 2010-02-04  7:58         ` Tero Tilus
  0 siblings, 0 replies; 5+ messages in thread
From: Tero Tilus @ 2010-02-04  7:58 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 608 bytes --]

Tero Tilus, 2010-01-25 04:05:
> William Morgan, 2010-01-23 15:11:
> > It's also important to call LabelManager.<< for each label, to
> > make sure they appear in label-list-mode.
> 
> I went a step further with this.  Counting on people not having
> billion-mail threads and gazillions of tags (and thus this
> potentially having performance implications) I dropped all the
> LabelManager.<< calls down to Message to ensure that every time
> labels change, LabelManager is informed.

...and that broke sup-dump.  Patch v3 (rebased to next) attached.

-- 
Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/

[-- Attachment #2: 0001-Message-edit_labels.patch --]
[-- Type: application/octet-stream, Size: 8196 bytes --]

From 7f4499998c3708e3916804c079829537e67a06c7 Mon Sep 17 00:00:00 2001
From: Tero Tilus <tero@tilus.net>
Date: Thu, 4 Feb 2010 09:31:34 +0200
Subject: [PATCH] Message#edit_labels

 - updating labels using "diff" factored out to Message
 - pushing labels to LabelManager in Message (only) to ensure
   up-to-date label list in LabelManager

Signed-off-by: Tero Tilus <tero@tilus.net>
---
 bin/sup-dump                       |   15 ++++++++++-----
 lib/sup/message.rb                 |   17 +++++++++++++++++
 lib/sup/modes/thread-index-mode.rb |   19 ++-----------------
 lib/sup/modes/thread-view-mode.rb  |    1 -
 lib/sup/poll.rb                    |    1 -
 lib/sup/thread.rb                  |    7 ++++++-
 lib/sup/util.rb                    |   31 ++++++++++++++++++++++++++++---
 lib/sup/xapian_index.rb            |    1 -
 8 files changed, 63 insertions(+), 29 deletions(-)

diff --git a/bin/sup-dump b/bin/sup-dump
index b738915..46a517e 100755
--- a/bin/sup-dump
+++ b/bin/sup-dump
@@ -22,10 +22,15 @@ EOS
   opt :index, "Use this index type ('auto' for autodetect)", :default => "auto"
 end
 
-index = Redwood::Index.init $opts[:index]
-Redwood::SourceManager.init
-index.load
+begin
+  index = Redwood::Index.init $opts[:index]
+  Redwood::LabelManager.init Redwood::LABEL_FN
+  Redwood::SourceManager.init
+  index.load
 
-index.each_message :load_spam => true, :load_deleted => true, :load_killed => true do |m|
-  puts "#{m.id} (#{m.labels.to_a.sort_by { |l| l.to_s } * ' '})"
+  index.each_message :load_spam => true, :load_deleted => true, :load_killed => true do |m|
+    puts "#{m.id} (#{m.labels.to_a.sort_by { |l| l.to_s } * ' '})"
+  end
+ensure
+  Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
 end
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index a85cc0d..eb4728d 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -48,6 +48,7 @@ class Message
     @snippet_contains_encrypted_content = false
     @have_snippet = !(opts[:snippet].nil? || opts[:snippet].empty?)
     @labels = Set.new(opts[:labels] || [])
+    @labels.each { |l| LabelManager << l }
     @dirty = false
     @encrypted = false
     @chunks = nil
@@ -198,6 +199,7 @@ class Message
     l = l.to_sym
     return if @labels.member? l
     @labels << l
+    LabelManager << l
     @dirty = true
   end
   def remove_label l
@@ -207,6 +209,20 @@ class Message
     @dirty = true
   end
 
+  ## Takes either a String or a Set of SignedSymbols.  Edits labels
+  ## accordingly.  Calling m.edit_labels 'foo -index +bar' adds labels
+  ## foo and bar and removes label index.
+  def edit_labels labels
+    labels = labels.to_ssym if labels.is_a? String
+    labels.each do |signedlabel|
+      if signedlabel.sign == :-
+        remove_label signedlabel.sym
+      else
+        add_label signedlabel.sym
+      end
+    end
+  end
+
   def recipients
     @to + @cc + @bcc
   end
@@ -215,6 +231,7 @@ class Message
     raise ArgumentError, "not a set" unless l.is_a?(Set)
     raise ArgumentError, "not a set of labels" unless l.all? { |ll| ll.is_a?(Symbol) }
     return if @labels == l
+    (l - @labels).each { |ll| LabelManager << ll }
     @labels = l
     @dirty = true
   end
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index a6bb2b9..4cbc1f1 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -536,7 +536,6 @@ EOS
     return unless user_labels
 
     thread.labels = Set.new(keepl) + user_labels
-    user_labels.each { |l| LabelManager << l }
     update_text_for_line curpos
 
     UndoManager.register "labeling thread" do
@@ -554,24 +553,11 @@ EOS
     user_labels = BufferManager.ask_for_labels :labels, "Add/remove labels (use -label to remove): ", [], @hidden_labels
     return unless user_labels
 
-    user_labels.map! { |l| (l.to_s =~ /^-/)? [l.to_s.gsub(/^-?/, '').to_sym, true] : [l, false] }
-    hl = user_labels.select { |(l,_)| @hidden_labels.member? l }
-    unless hl.empty?
-      BufferManager.flash "'#{hl}' is a reserved label!"
-      return
-    end
-
+    user_labels = user_labels.to_set_of_signed_symbols
     old_labels = threads.map { |t| t.labels.dup }
 
     threads.each do |t|
-      user_labels.each do |(l, to_remove)|
-        if to_remove
-          t.remove_label l
-        else
-          t.apply_label l
-          LabelManager << l
-        end
-      end
+      t.edit_labels user_labels
       UpdateManager.relay self, :labeled, t.first
     end
 
@@ -637,7 +623,6 @@ EOS
       ::Thread.pass
       break if @interrupt_search
     end
-    @ts.threads.each { |th| th.labels.each { |l| LabelManager << l } }
 
     update
     BufferManager.clear @mbid
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
index 0e935a4..9233873 100644
--- a/lib/sup/modes/thread-view-mode.rb
+++ b/lib/sup/modes/thread-view-mode.rb
@@ -273,7 +273,6 @@ EOS
 
     return unless new_labels
     @thread.labels = Set.new(reserved_labels) + new_labels
-    new_labels.each { |l| LabelManager << l }
     update
     UpdateManager.relay self, :labeled, @thread.first
     Index.save_thread @thread
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
index f3e1224..104bd70 100644
--- a/lib/sup/poll.rb
+++ b/lib/sup/poll.rb
@@ -163,7 +163,6 @@ EOS
         m = Message.build_from_source source, offset
         m.labels += source_labels + (source.archived? ? [] : [:inbox])
         m.labels.delete :unread if m.source_marked_read? # preserve read status if possible
-        m.labels.each { |l| LabelManager << l }
 
         HookManager.run "before-add-message", :message => m
         yield m
diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb
index 3fdf1f6..f159e5f 100644
--- a/lib/sup/thread.rb
+++ b/lib/sup/thread.rb
@@ -110,7 +110,6 @@ class Thread
     end
   end
 
-  def set_labels l; each { |m, *o| m && m.labels = l }; end
   def has_label? t; any? { |m, *o| m && m.has_label?(t) }; end
   def each_dirty_message; each { |m, *o| m && m.dirty? && yield(m) }; end
 
@@ -130,6 +129,12 @@ class Thread
     each { |m, *o| m && m.labels = l.dup }
   end
 
+  ## see Message#edit_labels
+  def edit_labels labels
+    labels = labels.to_ssym if labels.is_a? String
+    each { |m, *o| m.edit_labels labels }
+  end
+
   def latest_message
     inject(nil) do |a, b|
       b = b.first
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index 861db7f..e2d8c5d 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -296,12 +296,20 @@ class String
     end
   end
 
-  ## takes a list of words, and returns an array of symbols.  typically used in
+  ## Takes a list of words, and returns a set of given transforms.  Typically used in
   ## Sup for translating Ferret's representation of a list of labels (a string)
-  ## to an array of label symbols.
+  ## to an array of label symbols (see #to_set_of_symbols).
   ##
   ## split_on will be passed to String#split, so you can leave this nil for space.
-  def to_set_of_symbols split_on=nil; Set.new split(split_on).map { |x| x.strip.intern } end
+  def to_set_of mapping, split_on=nil; Set.new split(split_on).map { |x| x.strip.send mapping } end
+
+  def to_set_of_symbols split_on=nil; to_set_of :to_sym, split_on; end
+  def to_set_of_signed_symbols split_on=nil; to_set_of :to_ssym, split_on; end
+
+  def to_ssym
+    dummy, sign, label = self.match(/^(-|\+)?(.*)$/).to_a
+    SignedSymbol.new label.to_sym, ( sign=='-' ? :- : :+ )
+  end
 
   class CheckError < ArgumentError; end
   def check
@@ -331,6 +339,23 @@ class String
   end
 end
 
+class SignedSymbol
+  def initialize sym, sign
+    @sym = sym
+    @sign = sign
+  end
+  def sym; @sym; end
+  def sign; @sign; end
+end
+
+class Symbol
+  def to_ssym; to_s.to_ssym; end
+end
+
+class Set
+  def to_set_of_signed_symbols; map(&:to_ssym); end
+end
+
 class Numeric
   def clamp min, max
     if self < min
diff --git a/lib/sup/xapian_index.rb b/lib/sup/xapian_index.rb
index 443b88d..c2867cf 100644
--- a/lib/sup/xapian_index.rb
+++ b/lib/sup/xapian_index.rb
@@ -466,7 +466,6 @@ EOS
       @xapian.replace_document docid, doc
     end
 
-    m.labels.each { |l| LabelManager << l }
     true
   end
 
-- 
1.5.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-02-04  7:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1263574849-sup-3477@sam.mediasupervision.de>
2010-01-16 22:41 ` [sup-devel] [PATCH] Message#edit_labels [was: [sup-talk] Ruby question: before-add-message.rb and adding multiple labels at once] Tero Tilus
2010-01-21 23:51   ` [sup-devel] [PATCH] Message#edit_labels [was: " Tero Tilus
2010-01-23 13:11     ` William Morgan
2010-01-25  2:05       ` Tero Tilus
2010-02-04  7:58         ` Tero Tilus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox