Class: Nauvisian::CLI::Commands::Save::Mod::Sync::ExistingMods

Inherits:
Object
  • Object
show all
Includes:
DownloadHelper, MessageHelper
Defined in:
lib/nauvisian/cli/commands/save/mod/sync.rb

Instance Method Summary collapse

Constructor Details

#initialize(mod_directory:, exact:, verbose:) ⇒ ExistingMods

Returns a new instance of ExistingMods.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/nauvisian/cli/commands/save/mod/sync.rb', line 56

def initialize(mod_directory:, exact:, verbose:)
  @exact = exact
  @verbose = verbose

  zips = mod_directory.glob("*.zip")
  directories = mod_directory.entries.select(&:directory?)
  # [[mod, [version...]]
  @mods = [*zips, *directories].filter_map {|path|
    /(?<name>.*)_(?<version>\d+\.\d+\.\d+)(?:\.zip|$)\z/ =~ path.basename.to_s && [Nauvisian::Mod[name:], Nauvisian::Version24[version]]
  }.group_by(&:first).transform_values {|v| v.map(&:last) }.to_a
end

Instance Method Details

#exact?Boolean

Returns:

  • (Boolean)


68
# File 'lib/nauvisian/cli/commands/save/mod/sync.rb', line 68

def exact? = @exact

#release_to_download(mod, version) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/nauvisian/cli/commands/save/mod/sync.rb', line 71

def release_to_download(mod, version)
  message "⚙ Checking #{mod.name} #{version} ... "

  # TODO: Take version requirement into consideration
  case @mods
  in [*, [^mod, [*, ^version, *]], *]
    message "✓ Exact version (#{version}) exists, nothing to do"
  in [*, [^mod, [*versions]], *]
    if exact?
      message "📥 some versions are installed but exact version (#{version}) is requested"
      find_release(mod, version:)
    elsif versions.all? {|v| v < version }
      message "📥 all versions are older than the version in the save (#{version}), downloading the latest"
      find_release(mod)
    else
      message "✓ newer version exists, nothing to do"
    end
  else
    message "📥 MOD is not installed"
    exact? ? find_release(mod, version:) : find_release(mod)
  end
end

#verbose?Boolean

Returns:

  • (Boolean)


69
# File 'lib/nauvisian/cli/commands/save/mod/sync.rb', line 69

def verbose? = @verbose