Class: Mail::TestRetriever
- Inherits:
-
Object
- Object
- Mail::TestRetriever
- Defined in:
- lib/kns_email_endpoint/core_extensions/test_retriever.rb
Instance Method Summary collapse
- #delete_all ⇒ Object
-
#find(options = {}, &block) ⇒ Object
Fix a bug in the find method when only returning a single email.
Instance Method Details
#delete_all ⇒ Object
5 6 7 |
# File 'lib/kns_email_endpoint/core_extensions/test_retriever.rb', line 5 def delete_all @@emails = [] end |
#find(options = {}, &block) ⇒ Object
Fix a bug in the find method when only returning a single email
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kns_email_endpoint/core_extensions/test_retriever.rb', line 12 def find( = {}, &block) [:count] ||= :all [:order] ||= :asc [:what] ||= :first emails = @@emails.dup emails.reverse! if [:what] == :last emails = case count = [: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 [:what] == :last && [:order] == :asc || [:what] == :first && [:order] == :desc emails.reverse! end emails.each { |email| email.mark_for_delete = true } if [: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 [:delete_after_find] end return emails.size == 1 && [:count] == 1 ? emails.first : emails end |