Sha256: 9309319bf331bcea3ef7336f0a62ac5aad65a80f4fa98f11b69bffd6bacef83d

Contents?: true

Size: 451 Bytes

Versions: 1

Compression:

Stored size: 451 Bytes

Contents

require 'cinch/storage/version'
require 'psych'

class CinchStorage
  attr_accessor :filename, :data

  def initialize(file, init = Hash.new)
    @filename = file
    @data = YAML::load(File.open(@filename)) if File::exist?(@filename)
    @data ||= init
  end

  def save
    File.open(@filename, 'w') do |file|
      YAML::dump(@data, file)
    end
  end

  def synced_save(bot = @bot)
    bot.synchronize(@filename) do
      save
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cinch-storage-1.0.0 lib/cinch-storage.rb