Class: Rufio::BookmarkMigrator
- Inherits:
-
Object
- Object
- Rufio::BookmarkMigrator
- Defined in:
- lib/rufio/bookmark_storage.rb
Overview
JSONからYAMLへのマイグレーター
Class Method Summary collapse
-
.migrate(json_path, yaml_path) ⇒ Boolean
マイグレーションが実行されたかどうか.
Class Method Details
.migrate(json_path, yaml_path) ⇒ Boolean
Returns マイグレーションが実行されたかどうか.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/rufio/bookmark_storage.rb', line 127 def self.migrate(json_path, yaml_path) return false unless File.exist?(json_path) # JSONからブックマークを読み込む json_storage = JsonBookmarkStorage.new(json_path) bookmarks = json_storage.load return false if bookmarks.empty? # YAMLに保存 yaml_storage = YamlBookmarkStorage.new(yaml_path) yaml_storage.save(bookmarks) # JSONファイルをバックアップ FileUtils.mv(json_path, "#{json_path}.bak") true rescue StandardError => e warn "Migration failed: #{e.}" false end |