Class: Hermeneutics::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/hermeneutics/boxes.rb

Overview

Mailboxes

Direct Known Subclasses

MBox, Maildir

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mailbox) ⇒ Box

:call-seq:

Box.new( path)          -> box

Instantiate a Box object, just store the path.



76
77
78
# File 'lib/hermeneutics/boxes.rb', line 76

def initialize mailbox
  @mailbox = mailbox
end

Class Method Details

.check(path) ⇒ Object

:call-seq:

Box.check( path)     -> nil

By default, subclass mailboxes do not exist. You should overwrite this behaviour.



60
61
# File 'lib/hermeneutics/boxes.rb', line 60

def check path
end

.find(path, default_format = nil) ⇒ Object

:call-seq:

Box.find( path, default = nil)          -> box

Create a Box object (some subclass of Box), depending on what type the box is found at path.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hermeneutics/boxes.rb', line 40

def find path, default_format = nil
  b = @boxes.find { |b| b.check path }
  b ||= default_format
  b ||= if File.directory? path then
    Maildir
  elsif File.file? path then
    MBox
  else
    # If still nothing was found use Postfix convention:
    path =~ /\/$/ ? Maildir : MBox
  end
  b.new path
end

Instance Method Details

#exists?Boolean

:call-seq:

box.exists?     -> true or false

Test whether the Box exists.

Returns:

  • (Boolean)


89
90
91
# File 'lib/hermeneutics/boxes.rb', line 89

def exists?
  self.class.check @mailbox
end

#pathObject



82
# File 'lib/hermeneutics/boxes.rb', line 82

def path ; @mailbox ; end

#to_sObject



80
# File 'lib/hermeneutics/boxes.rb', line 80

def to_s ; path ; end