Sha256: d20c7d808c26a6bbe4d055e2907c0e583a06414b71eb98739815a8a67c73f1ad

Contents?: true

Size: 962 Bytes

Versions: 4

Compression:

Stored size: 962 Bytes

Contents

module Redwood

class LabelManager
  include Singleton

  ## labels that have special semantics. user will be unable to
  ## add/remove these via normal label mechanisms.
  RESERVED_LABELS = [ :starred, :spam, :draft, :unread, :killed, :sent ]

  ## labels which it nonetheless makes sense to search for by
  LISTABLE_LABELS = [ :starred, :spam, :draft, :sent ]

  ## labels that will never be displayed to the user
  HIDDEN_LABELS = [ :starred, :unread ]

  def initialize fn
    @fn = fn
    labels = 
      if File.exists? fn
        IO.readlines(fn).map { |x| x.chomp.intern }
      else
        []
      end
    @labels = {}
    labels.each { |t| @labels[t] = true }

    self.class.i_am_the_instance self
  end

  def user_labels; @labels.keys; end
  def << t; @labels[t] = true unless @labels.member?(t) || RESERVED_LABELS.member?(t); end
  def delete t; @labels.delete t; end
  def save
    File.open(@fn, "w") { |f| f.puts @labels.keys }
  end
end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sup-0.0.6 lib/sup/label.rb
sup-0.0.4 lib/sup/label.rb
sup-0.0.5 lib/sup/label.rb
sup-0.0.3 lib/sup/label.rb