Sha256: f188d42c6601a044c9bdafd2ab067ad1f6182d634eef6575d8cf9788910bbcbe

Contents?: true

Size: 1.66 KB

Versions: 2

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

# Copyright (C) 2016, 2017 Szymon Kopciewski
#
# This file is part of MayamlMutt.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

module MayamlMutt
  class ConfigsGenerator
    def initialize(init_templater, alternates_templater, creds_templater)
      @init_templater = init_templater
      @alternates_templater = alternates_templater
      @creds_templater = creds_templater
    end

    def generates_init(accounts)
      alternates = []
      accounts.each_with_object({}) do |mail_account, result|
        key = mail_account.name.to_sym
        alternates << mail_account.name
        result[key] = @init_templater.render(mail_account)
        result[:alternates] = @alternates_templater.render(alternates)
        result
      end
    end

    def generates_creds(accounts)
      accounts.each_with_object({}) do |mail_account, result|
        key = mail_account.name.to_sym
        result[key] = @creds_templater.render(mail_account)
        result[:default] = mail_account.name if mail_account.default || !result.key?(:default)
        result
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mayaml-mutt-4.0.1 lib/mayaml-mutt/configs_generator.rb
mayaml-mutt-4.0.0 lib/mayaml-mutt/configs_generator.rb