Sha256: d44fa060cb592b426708535d29c3144b118eed33500b87e7db14bd634bafd6fd

Contents?: true

Size: 1 KB

Versions: 20

Compression:

Stored size: 1 KB

Contents

class SlackSmartBot
  def update_bots_file
    bots_file = config.file_path.gsub(".rb", "_bots.yaml")

    if File.exist?(config.file_path.gsub(".rb", "_bots.rb")) #backwards compatible
      file_conf = IO.readlines(config.file_path.gsub(".rb", "_bots.rb")).join
      if file_conf.to_s() == ""
        @bots_created = {}
      else
        @bots_created = eval(file_conf)
      end      
      File.open(bots_file, 'w') {|file| 
        file.flock(File::LOCK_EX)
        file.write(@bots_created.to_yaml) 
        file.flock(File::LOCK_UN)
      }
      File.delete(config.file_path.gsub(".rb", "_bots.rb"))
    else
      #not possible to use @bots_created.deep_copy since one of the fields contains a thread
      bots_created = {}
      @bots_created.each do |k,v|
        bots_created[k] = v.dup
        bots_created[k][:thread] = ''
      end
      File.open(bots_file, 'w') {|file|
        file.flock(File::LOCK_EX)
        file.write(bots_created.to_yaml) 
        file.flock(File::LOCK_UN)
      }
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
slack-smart-bot-1.15.25 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.15.1 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.15.0 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.14.2 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.14.1 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.14.0 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.13.2 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.13.1 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.13.0 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.9 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.8 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.7 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.6 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.5 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.4 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.3 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.2 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.1 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.12.0 lib/slack/smart-bot/utils/update_bots_file.rb
slack-smart-bot-1.11.0 lib/slack/smart-bot/utils/update_bots_file.rb