Class: Rufio::JsonBookmarkStorage

Inherits:
BookmarkStorage show all
Defined in:
lib/rufio/bookmark_storage.rb

Overview

JSON形式のブックマークストレージ

Instance Method Summary collapse

Methods inherited from BookmarkStorage

#initialize

Constructor Details

This class inherits a constructor from Rufio::BookmarkStorage

Instance Method Details

#loadObject



52
53
54
55
56
57
58
59
60
# File 'lib/rufio/bookmark_storage.rb', line 52

def load
  return [] unless File.exist?(@file_path)

  content = File.read(@file_path)
  bookmarks = JSON.parse(content, symbolize_names: true)
  filter_valid_bookmarks(bookmarks)
rescue JSON::ParserError, StandardError
  []
end

#save(bookmarks) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/rufio/bookmark_storage.rb', line 62

def save(bookmarks)
  ensure_directory
  File.write(@file_path, JSON.pretty_generate(bookmarks))
  true
rescue StandardError => e
  warn "Failed to save bookmarks to JSON: #{e.message}"
  false
end