Class: Redwood::DraftLoader

Inherits:
Source show all
Defined in:
lib/sup/draft.rb

Instance Attribute Summary (collapse)

Attributes inherited from Source

#cur_offset

Instance Method Summary (collapse)

Methods inherited from Source

#==, #check, #done?, #file_path, #is_source_for?, #reset!, #seek_to!

Constructor Details

- (DraftLoader) initialize(cur_offset = 0)

Returns a new instance of DraftLoader



50
51
52
53
54
55
# File 'lib/sup/draft.rb', line 50

def initialize cur_offset=0
  dir = Redwood::DRAFT_DIR
  Dir.mkdir dir unless File.exists? dir
  super DraftManager.source_name, cur_offset, true, false
  @dir = dir
end

Instance Attribute Details

- (Object) dir

Returns the value of attribute dir



47
48
49
# File 'lib/sup/draft.rb', line 47

def dir
  @dir
end

Instance Method Details

- (Object) each



61
62
63
64
65
66
67
68
69
# File 'lib/sup/draft.rb', line 61

def each
  ids = get_ids
  ids.each do |id|
    if id >= cur_offset
      self.cur_offset = id + 1
      yield [id, [:draft, :inbox]]
    end
  end
end

- (Object) each_raw_message_line(offset)



105
106
107
108
109
# File 'lib/sup/draft.rb', line 105

def each_raw_message_line offset
  File.open(fn_for_offset(offset)) do |f|
    yield f.gets until f.eof?
  end
end

- (Object) end_offset



116
117
118
119
# File 'lib/sup/draft.rb', line 116

def end_offset
  ids = get_ids
  ids.empty? ? 0 : (ids.last + 1)
end

- (Object) fn_for_offset(o)



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

def fn_for_offset o; File.join(@dir, o.to_s); end

- (Object) gen_offset



71
72
73
74
75
76
77
# File 'lib/sup/draft.rb', line 71

def gen_offset
  i = cur_offset
  while File.exists? fn_for_offset(i)
    i += 1
  end
  i
end

- (Object) id



57
# File 'lib/sup/draft.rb', line 57

def id; DraftManager.source_id; end

- (Object) load_header(offset)



81
82
83
84
85
# File 'lib/sup/draft.rb', line 81

def load_header offset
  File.open fn_for_offset(offset) do |f|
    return MBox::read_header(f)
  end
end

- (Object) load_message(offset)



87
88
89
90
91
92
93
# File 'lib/sup/draft.rb', line 87

def load_message offset
  File.open fn_for_offset(offset) do |f|
    RMail::Mailbox::MBoxReader.new(f).each_message do |input|
      return RMail::Parser.read(input)
    end
  end
end

- (Object) raw_header(offset)



95
96
97
98
99
100
101
102
103
# File 'lib/sup/draft.rb', line 95

def raw_header offset
  ret = ""
  File.open fn_for_offset(offset) do |f|
    until f.eof? || (l = f.gets) =~ /^$/
      ret += l
    end
  end
  ret
end

- (Object) raw_message(offset)



111
112
113
# File 'lib/sup/draft.rb', line 111

def raw_message offset
  IO.read(fn_for_offset(offset))
end

- (Object) start_offset



115
# File 'lib/sup/draft.rb', line 115

def start_offset; 0; end

- (Object) to_s



58
# File 'lib/sup/draft.rb', line 58

def to_s; DraftManager.source_name; end

- (Object) uri



59
# File 'lib/sup/draft.rb', line 59

def uri; DraftManager.source_name; end