Sha256: f4f13d65db52c4c6959e2e202746c18c145cf3a06af1bef2b0f933d382b78c48

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

module Mail

  class TestRetriever < Retriever

    def self.emails
      @@emails
    end

    def self.emails=(val)
      @@emails = val
    end

    def initialize(values)
      @@emails = []
    end

    def find(options = {}, &block)
      options[:count] ||= :all
      options[:order] ||= :asc
      options[:what] ||= :first
      emails_index = (0...@@emails.size).to_a
      emails_index.reverse! if options[:what] == :last
      emails_index = case count = options[:count]
        when :all then emails_index
        when Fixnum then emails_index[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_index.reverse!
      end
      emails_index.each { |idx| @@emails[idx].mark_for_delete = true } if options[:delete_after_find]
      emails = emails_index.map { |idx| @@emails[idx] }
      emails.each { |email| yield email } if block_given?
      @@emails.reject!(&:is_marked_for_delete?) if options[:delete_after_find]
      emails.size == 1 && options[:count] == 1 ? emails.first : emails
    end

  end

end

Version data entries

15 entries across 14 versions & 5 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
tdiary-5.0.4 vendor/bundle/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
abaci-0.3.0 vendor/bundle/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
tdiary-5.0.2 vendor/bundle/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
tdiary-5.0.1 vendor/bundle/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/retriever_methods/test_retriever.rb
mail-2.6.4 lib/mail/network/retriever_methods/test_retriever.rb