Sha256: 444defdb8a0d6146d9ab5b9dd91c9d629cbe9253f5e03c705290989b93f4b805

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

class SlackSmartBot
  def get_teams
    @teams ||= {}
    old_teams_file = config.file_path.gsub(".rb", "_teams.yaml") #to be backward compatible
    require 'yaml'
    if File.exist?(old_teams_file)
      @logger.info 'Migrating teams to new format'
      teams = YAML.load(File.read(old_teams_file))
      @logger.info "@teams: #{teams.inspect}}"
      teams.each do |key, value|
        File.write(File.join(config.path, "teams", "t_#{key}.yaml"), Utils::Encryption.encrypt(value.to_yaml, config))
      end
      @logger.info "Deleting old_teams_file: #{old_teams_file}"
      File.delete(old_teams_file)
    end
    files = Dir.glob(File.join(config.path, "teams", "t_*.yaml"))
    @datetime_teams_file ||= {}
    files.each do |file|
      if !defined?(@datetime_teams_file) or !@datetime_teams_file.key?(file) or @datetime_teams_file[file] != File.mtime(file)
        teams_team = YAML.load(Utils::Encryption.decrypt(File.read(file),config))
        team_name = File.basename(file).gsub("t_","").gsub(".yaml","")
        teams_team[:name] = team_name unless teams_team.key?(:name) #to be backward compatible
        @teams[team_name.to_sym] = teams_team
        @datetime_teams_file[file] = File.mtime(file)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
slack-smart-bot-1.15.1 lib/slack/smart-bot/utils/get_teams.rb
slack-smart-bot-1.15.0 lib/slack/smart-bot/utils/get_teams.rb
slack-smart-bot-1.14.2 lib/slack/smart-bot/utils/get_teams.rb
slack-smart-bot-1.14.1 lib/slack/smart-bot/utils/get_teams.rb
slack-smart-bot-1.14.0 lib/slack/smart-bot/utils/get_teams.rb