Sha256: 1f530015c497b525af6dd1d343dafcd0687dbec771de37b86d6681e3e06771ad

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require "firestore"
require "tools/sync_helpers"

module Icarus
  module Mod
    module Tools
      # Sync methods
      class ModSync
        include SyncHelpers

        def initialize
          @firestore = Firestore.new
        end

        def mods
          @firestore.mods
        end

        def modinfo_array
          @modinfo_array ||= @firestore.modinfo_array.map do |url|
            retrieve_from_url(url)[:mods].map { |mod| Modinfo.new(mod) }
          rescue RequestFailed => e
            warn "Failed to retrieve modinfo: #{e.message}"
            next
          end.flatten.compact
        end

        def find_mod(modinfo)
          @firestore.find_mod(name: modinfo.name, author: modinfo.author)&.id
        end

        def find_modinfo(modinfo)
          @modinfo_array.find { |mod| mod.name == modinfo.name }
        end

        def update(modinfo)
          @firestore.update(:mod, modinfo, merge: false)
        end

        def delete(modinfo)
          @firestore.delete(:mod, modinfo)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Icarus-Mod-Tools-1.4.0 lib/icarus/mod/tools/mod_sync.rb