Sha256: 69b08edc0ea18f4982373817d0de75afd4d04ed7e0e8be1c0413783282e2a3cc

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

class SlackSmartBot
  def get_vacations
    @vacations ||= {}
    old_vacations_file = config.file_path.gsub(".rb", "_vacations.yaml") #to be backward compatible
    require 'yaml'
    if File.exist?(old_vacations_file)
      @logger.info 'Migrating vacations to new format'
      vacations = @vacations
      vacations = YAML.load(File.read(old_vacations_file))
      @vacations = vacations unless vacations.is_a?(FalseClass)
      @vacations.each do |key, value|
        File.write(File.join(config.path, "vacations", "v_#{key}.yaml"), Utils::Encryption.encrypt(value.to_yaml, config))
      end
      @logger.info "Deleting old_vacations_file: #{old_vacations_file}"
      File.delete(old_vacations_file)
    end
    files = Dir.glob(File.join(config.path, "vacations", "v_*.yaml"))
    @datetime_vacations_file ||= {}
    files.each do |file|
      if !defined?(@datetime_vacations_file) or !@datetime_vacations_file.key?(file) or @datetime_vacations_file[file] != File.mtime(file)
        vacations_user = YAML.load(Utils::Encryption.decrypt(File.read(file), config))
        @vacations[File.basename(file).gsub("v_","").gsub(".yaml","")] = vacations_user
        @datetime_vacations_file[file] = File.mtime(file)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slack-smart-bot-1.14.2 lib/slack/smart-bot/utils/get_vacations.rb
slack-smart-bot-1.14.1 lib/slack/smart-bot/utils/get_vacations.rb
slack-smart-bot-1.14.0 lib/slack/smart-bot/utils/get_vacations.rb