Class: Redwood::Source

Inherits:
Object show all
Defined in:
lib/sup/source.rb

Direct Known Subclasses

DraftLoader, IMAP, MBox::Loader, MBox::SSHLoader, Maildir

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, initial_offset = nil, usual = true, archived = false, id = nil) ⇒ Source

Returns a new instance of Source.

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
76
77
# File 'lib/sup/source.rb', line 68

def initialize uri, initial_offset=nil, usual=true, archived=false, id=nil
  raise ArgumentError, "id must be an integer: #{id.inspect}" unless id.is_a? Fixnum if id

  @uri = uri
  @cur_offset = initial_offset
  @usual = usual
  @archived = archived
  @id = id
  @dirty = false
end

Instance Attribute Details

#cur_offsetObject

Returns the value of attribute cur_offset.



65
66
67
# File 'lib/sup/source.rb', line 65

def cur_offset
  @cur_offset
end

#idObject

Returns the value of attribute id.



66
67
68
# File 'lib/sup/source.rb', line 66

def id
  @id
end

#uriObject (readonly)

Returns the value of attribute uri.



65
66
67
# File 'lib/sup/source.rb', line 65

def uri
  @uri
end

Instance Method Details

#==(o) ⇒ Object



84
# File 'lib/sup/source.rb', line 84

def == o; o.uri == uri; end

#checkObject

check should throw a FatalSourceError or an OutOfSyncSourcError if it can detect a problem. it is called when the sup starts up to proactively notify the user of any source problems.



91
# File 'lib/sup/source.rb', line 91

def check; end

#done?Boolean

Returns:

  • (Boolean)


85
# File 'lib/sup/source.rb', line 85

def done?; start_offset.nil? || (self.cur_offset ||= start_offset) >= end_offset; end

#eachObject



93
94
95
96
97
98
99
100
# File 'lib/sup/source.rb', line 93

def each
  self.cur_offset ||= start_offset
  until done?
    n, labels = self.next
    raise "no message" unless n
    yield n, labels
  end
end

#file_pathObject



79
# File 'lib/sup/source.rb', line 79

def file_path; nil end

#is_source_for?(uri) ⇒ Boolean

Returns:

  • (Boolean)


86
# File 'lib/sup/source.rb', line 86

def is_source_for? uri; uri == @uri; end

#reset!Object



83
# File 'lib/sup/source.rb', line 83

def reset!; seek_to! start_offset; end

#seek_to!(o) ⇒ Object



82
# File 'lib/sup/source.rb', line 82

def seek_to! o; self.cur_offset = o; end

#to_sObject



81
# File 'lib/sup/source.rb', line 81

def to_s; @uri.to_s; end

#usualObject

let’s begin!

dirty? means cur_offset has changed, so the source info needs to be re-saved to sources.yaml.



64
# File 'lib/sup/source.rb', line 64

bool_reader :usual, :archived, :dirty