lib/cinch-storage.rb in cinch-storage-0.0.2 vs lib/cinch-storage.rb in cinch-storage-1.0.0

- old
+ new

@@ -1,2 +1,25 @@ -require "cinch-storage/version" -require "cinch-storage/storage" +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 +