diff options
Diffstat (limited to 'new/lib/crys/pages_db_manager.rb')
-rw-r--r-- | new/lib/crys/pages_db_manager.rb | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/new/lib/crys/pages_db_manager.rb b/new/lib/crys/pages_db_manager.rb index 6a5e71c..029b035 100644 --- a/new/lib/crys/pages_db_manager.rb +++ b/new/lib/crys/pages_db_manager.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true + module Crys class PagesDbManager PAGES_KEY = :pages - PAGE = Struct.new(:filename, :file_path, :last_update, :in_rss, keyword_init: true) + PAGE = Struct.new(:filename, :file_path, :last_update, :in_rss, keyword_init: true) - def db_path - end + def db_path; end def add_page(processor) @processor = processor @@ -16,7 +17,7 @@ module Crys end def pages - db.fetch(:pages).map do | _, data| + db.fetch(:pages).map do |_, data| PAGE.new(data) end end @@ -25,7 +26,6 @@ module Crys attr_reader :hash, :processor - def db @db ||= YAML.load_file( db_path, @@ -34,15 +34,9 @@ module Crys end def upsert_db(hash, known_page) - if known_page - record = PAGE.new(known_page) - else - record = PAGE.new( - filename: processor.filename, - file_path: processor.file_path, - in_rss: true - ) - end + record = PAGE.new(known_page || { filename: processor.filename, + file_path: processor.file_path, + in_rss: true }) record.last_update = Time.now @@ -50,9 +44,7 @@ module Crys end def save_db - File.open(db_path, 'w') do |f| - f.write db.to_yaml - end + File.write(db_path, db.to_yaml) end def known_page(hash) |