Class: Icarus::Mod::Tools::Sync::Mods

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/icarus/mod/tools/sync/mods.rb

Overview

Sync methods

Instance Method Summary collapse

Methods included from Helpers

#retrieve_from_url

Constructor Details

#initialize(client: nil) ⇒ Mods

Returns a new instance of Mods.



14
15
16
# File 'lib/icarus/mod/tools/sync/mods.rb', line 14

def initialize(client: nil)
  @firestore = client || Firestore.new
end

Instance Method Details

#delete(modinfo) ⇒ Object



46
47
48
# File 'lib/icarus/mod/tools/sync/mods.rb', line 46

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

#find(modinfo) ⇒ Object



34
35
36
# File 'lib/icarus/mod/tools/sync/mods.rb', line 34

def find(modinfo)
  @firestore.find_by_type(type: "mods", name: modinfo.name, author: modinfo.author)&.id
end

#find_info(modinfo) ⇒ Object



38
39
40
# File 'lib/icarus/mod/tools/sync/mods.rb', line 38

def find_info(modinfo)
  @info_array.find { |mod| mod.name == modinfo.name }
end

#info_arrayObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/icarus/mod/tools/sync/mods.rb', line 22

def info_array
  @info_array ||= @firestore.modinfo.map do |url|
    retrieve_from_url(url)[:mods].map { |mod| Icarus::Mod::Tools::Modinfo.new(mod) if mod[:name].match?(/[a-z0-9]+/i) }
  rescue Icarus::Mod::Tools::Sync::RequestFailed
    warn "Skipped; Failed to retrieve #{url}"
    next
  rescue JSON::ParserError => e
    warn "Skipped; Invalid JSON: #{e.full_message}"
    next
  end.flatten.compact
end

#modsObject



18
19
20
# File 'lib/icarus/mod/tools/sync/mods.rb', line 18

def mods
  @firestore.mods
end

#update(modinfo) ⇒ Object



42
43
44
# File 'lib/icarus/mod/tools/sync/mods.rb', line 42

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