Sha256: ed2af475873da81fbdf4cf59c14e6010cad53d30d5728858b64b303b90536b11

Contents?: true

Size: 991 Bytes

Versions: 2

Compression:

Stored size: 991 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, :deleted ]

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

  ## 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

2 entries across 2 versions & 1 rubygems

Version Path
sup-0.0.8 lib/sup/label.rb
sup-0.0.7 lib/sup/label.rb