lib/ayadn/databases.rb in ayadn-1.1.1 vs lib/ayadn/databases.rb in ayadn-1.1.3

- old
+ new

@@ -2,27 +2,27 @@ module Ayadn class Databases class << self - attr_accessor :users, :index, :pagination, :aliases, :blacklist + attr_accessor :users, :index, :pagination, :aliases, :blacklist, :bookmarks end def self.open_databases @users = self.init "#{Settings.config[:paths][:db]}/users.db" @index = self.init "#{Settings.config[:paths][:pagination]}/index.db" @pagination = self.init "#{Settings.config[:paths][:pagination]}/pagination.db" @aliases = self.init "#{Settings.config[:paths][:db]}/aliases.db" @blacklist = self.init "#{Settings.config[:paths][:db]}/blacklist.db" + @bookmarks = self.init "#{Settings.config[:paths][:db]}/bookmarks.db" end def self.close_all - @pagination.compact if (File.size("#{Settings.config[:paths][:pagination]}/pagination.db") > (250000)) - @index.compact if (File.size("#{Settings.config[:paths][:pagination]}/index.db") > (250000)) - [@users, @index, @pagination, @aliases, @blacklist].each do |db| - db.flush - db.close + [@users, @index, @pagination, @aliases, @blacklist, @bookmarks].each do |db| + db.compact + db.flush + db.close end end def self.init(path) winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32'] @@ -122,9 +122,21 @@ @users[id] = {username => name} end def self.has_new?(stream, title) stream['meta']['max_id'].to_i > @pagination[title].to_i + end + + def self.add_bookmark bookmark + @bookmarks[bookmark[:id]] = bookmark + end + + def self.delete_bookmark post_id + @bookmarks.delete post_id + end + + def self.rename_bookmark post_id, new_title + @bookmarks[post_id][:title] = new_title end end end