Sha256: df1a09d811641ed7acbf37a6f66ef80604212098d03514842e2fd20399780381

Contents?: true

Size: 967 Bytes

Versions: 10

Compression:

Stored size: 967 Bytes

Contents

require "pathname"

require "imap/backup/account/folder"
require "imap/backup/account/folder_ensurer"
require "imap/backup/serializer"

module Imap; end

module Imap::Backup
  class Account; end

  class Account::SerializedFolders
    include Enumerable

    attr_reader :account

    def initialize(account:)
      @account = account
    end

    def each(&block)
      return enum_for(:each) if !block

      glob.each do |path|
        name = path.relative_path_from(base).to_s[0..-6]
        serializer = Serializer.new(account.local_path, name)
        folder = Account::Folder.new(account.client, name)
        block.call(serializer, folder)
      end
    end

    private

    def base
      @base ||= Pathname.new(account.local_path)
    end

    def glob
      @glob ||= begin
        Account::FolderEnsurer.new(account: account).run

        pattern = File.join(account.local_path, "**", "*.imap")
        Pathname.glob(pattern)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
imap-backup-14.4.1 lib/imap/backup/account/serialized_folders.rb
imap-backup-14.4.0 lib/imap/backup/account/serialized_folders.rb
imap-backup-14.3.0 lib/imap/backup/account/serialized_folders.rb
imap-backup-14.2.0 lib/imap/backup/account/serialized_folders.rb
imap-backup-14.1.1 lib/imap/backup/account/serialized_folders.rb
imap-backup-14.1.0 lib/imap/backup/account/serialized_folders.rb
imap-backup-14.0.0 lib/imap/backup/account/serialized_folders.rb
imap-backup-13.4.0 lib/imap/backup/account/serialized_folders.rb
imap-backup-13.3.0 lib/imap/backup/account/serialized_folders.rb
imap-backup-13.2.0 lib/imap/backup/account/serialized_folders.rb