Sha256: 9103bba9af6f200e8f8f65e40000bd2e759f01690bd0323fd1af69c57f1ffdd5

Contents?: true

Size: 1.26 KB

Versions: 14

Compression:

Stored size: 1.26 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 = nil, &block)
      options = options ? Hash[options] : {}
      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 Integer 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

14 entries across 14 versions & 5 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/network/retriever_methods/test_retriever.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/network/retriever_methods/test_retriever.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/retriever_methods/test_retriever.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/retriever_methods/test_retriever.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/retriever_methods/test_retriever.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.1 lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.1.rc2 lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.0.1 lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.0.1.rc1 lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.0 lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.0.rc3 lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.0.rc2 lib/mail/network/retriever_methods/test_retriever.rb
mail-2.8.0.rc1 lib/mail/network/retriever_methods/test_retriever.rb