Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 44 lines (35 sloc) 1.215 kB
2e5f50e @dball Add test retriever
dball authored
1 # encoding: utf-8
2
3 module Mail
4
75888e2 @dball Extract base retriever class
dball authored
5 class TestRetriever < Retriever
5a737d6 @mikel Removing cattr_accessor calls for 1.8.7 compat
authored
6
7 def self.emails
8 @@emails
9 end
10
11 def self.emails=(val)
12 @@emails = val
13 end
2e5f50e @dball Add test retriever
dball authored
14
15 def initialize(values)
16 @@emails = []
17 end
18
19 def find(options = {}, &block)
b5641ef @dball Flesh out test retriever API to conform to the intersection of the PO…
dball authored
20 options[:count] ||= :all
21 options[:order] ||= :asc
22 options[:what] ||= :first
ec23f73 @ermaker Fix a bug of TestRetriever with same emails of INBOX
ermaker authored
23 emails_index = (0...@@emails.size).to_a
24 emails_index.reverse! if options[:what] == :last
25 emails_index = case count = options[:count]
26 when :all then emails_index
27 when Fixnum then emails_index[0, count]
2e5f50e @dball Add test retriever
dball authored
28 else
b5641ef @dball Flesh out test retriever API to conform to the intersection of the PO…
dball authored
29 raise 'Invalid count option value: ' + count.inspect
30 end
31 if options[:what] == :last && options[:order] == :asc || options[:what] == :first && options[:order] == :desc
ec23f73 @ermaker Fix a bug of TestRetriever with same emails of INBOX
ermaker authored
32 emails_index.reverse!
b5641ef @dball Flesh out test retriever API to conform to the intersection of the PO…
dball authored
33 end
ec23f73 @ermaker Fix a bug of TestRetriever with same emails of INBOX
ermaker authored
34 emails_index.each { |idx| @@emails[idx].mark_for_delete = true } if options[:delete_after_find]
35 emails = emails_index.map { |idx| @@emails[idx] }
e9630e1 @ermaker Fix a bug of TestRetriever with :count => 1
ermaker authored
36 emails.each { |email| yield email } if block_given?
ec23f73 @ermaker Fix a bug of TestRetriever with same emails of INBOX
ermaker authored
37 @@emails.reject!(&:is_marked_for_delete?) if options[:delete_after_find]
e9630e1 @ermaker Fix a bug of TestRetriever with :count => 1
ermaker authored
38 emails.size == 1 && options[:count] == 1 ? emails.first : emails
2e5f50e @dball Add test retriever
dball authored
39 end
40
41 end
42
43 end
Something went wrong with that request. Please try again.