Class: Mail::TestRetriever
- Inherits:
-
Retriever
show all
- Defined in:
- lib/mail/network/retriever_methods/test_retriever.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Retriever
#all, #find_and_delete, #first, #last
Constructor Details
Returns a new instance of TestRetriever.
15
16
17
|
# File 'lib/mail/network/retriever_methods/test_retriever.rb', line 15
def initialize(values)
@@emails = []
end
|
Class Method Details
7
8
9
|
# File 'lib/mail/network/retriever_methods/test_retriever.rb', line 7
def self.emails
@@emails
end
|
.emails=(val) ⇒ Object
11
12
13
|
# File 'lib/mail/network/retriever_methods/test_retriever.rb', line 11
def self.emails=(val)
@@emails = val
end
|
Instance Method Details
#find(options = {}, &block) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/mail/network/retriever_methods/test_retriever.rb', line 19
def find(options = {}, &block)
options[:count] ||= :all
options[:order] ||= :asc
options[:what] ||= :first
emails = @@emails.dup
emails.reverse! if options[:what] == :last
emails = case count = options[:count]
when :all then emails
when 1 then emails.first
when Fixnum then emails[0, count]
else
raise 'Invalid count option value: ' + count.inspect
end
if options[:what] == :last && options[:order] == :asc || options[:what] == :first && options[:order] == :desc
emails.reverse!
end
emails.each { |email| email.mark_for_delete = true } if options[:delete_after_find]
if block_given?
emails.each { |email| yield email }
else
emails
end.tap do |results|
emails.each { |email| @@emails.delete(email) if email.is_marked_for_delete? } if options[:delete_after_find]
end
end
|