class U3d::UnityModule

Attributes

checksum[R]

Validation attributes

command[R]

Internal attributes

depends_on[R]

Internal attributes

description[R]

Basic module attributes

destination[R]

Internal attributes

download_size[R]

Validation attributes

id[R]

Basic module attributes

installed_size[R]

Validation attributes

name[R]

Basic module attributes

os[R]

Internal attributes

rename_from[R]

Internal attributes

rename_to[R]

Internal attributes

url[R]

Basic module attributes

Public Class Methods

load_modules(version, cached_versions, os: U3dCore::Helper.operating_system, offline: false) click to toggle source
# File lib/u3d/unity_module.rb, line 62
def load_modules(version, cached_versions, os: U3dCore::Helper.operating_system, offline: false)
  if version.is_a? Array
    UI.verbose "Loading modules for several versions: #{version}"
    load_versions_modules(version, cached_versions, os, offline)
  else
    UI.verbose "Loading modules for version #{version}"
    load_version_modules(version, cached_versions, os, offline)
  end
end
new( id:, name: nil, description: nil, url: nil, installed_size: nil, download_size: nil, checksum: nil, os: nil, depends_on: nil, command: nil, destination: nil, rename_from: nil, rename_to: nil ) click to toggle source

rubocop:disable Metrics/ParameterLists

# File lib/u3d/unity_module.rb, line 33
def initialize(
  id:, name: nil, description: nil, url: nil,
  installed_size: nil, download_size: nil, checksum: nil,
  os: nil, depends_on: nil, command: nil, destination: nil, rename_from: nil, rename_to: nil
)
  @id = id.downcase
  @name = name
  @description = description
  @url = url
  @installed_size = installed_size
  @download_size = download_size
  @checksum = checksum
  @os = os
  @depends_on = depends_on
  @command = command
  @destination = destination
  @rename_from = rename_from
  @rename_to = rename_to
end

Private Class Methods

load_version_modules(version, cached_versions, os, offline) click to toggle source
# File lib/u3d/unity_module.rb, line 97
def load_version_modules(version, cached_versions, os, offline)
  ini_data = INIModulesParser.load_ini(version, cached_versions, os: os, offline: offline)
  url_root = cached_versions[version]
  ini_modules = ini_data.map { |k, v| module_from_ini_data(k, v, url_root, os) }

  json_data = HubModulesParser.load_modules(version, os: os, offline: offline)
  json_modules = json_data.map { |data| module_from_json_data(data, os) }

  return (ini_modules + json_modules).uniq(&:id)
end
load_versions_modules(versions, cached_versions, os, offline) click to toggle source

Optimized version of load_version_modules that only makes one HTTP call

# File lib/u3d/unity_module.rb, line 75
def load_versions_modules(versions, cached_versions, os, offline)
  ini_modules = versions
                .map { |version| [version, INIModulesParser.load_ini(version, cached_versions, os: os, offline: offline)] }
                .map do |version, ini_data|
    url_root = cached_versions[version]
    modules = ini_data.map { |k, v| module_from_ini_data(k, v, url_root, os) }
    [version, modules]
  end.to_h

  HubModulesParser.download_modules(os: os) unless offline
  hub_modules = versions
                .map { |version| [version, HubModulesParser.load_modules(version, os: os, offline: true)] }
                .map do |version, json_data|
    modules = json_data.map { |data| module_from_json_data(data, os) }
    [version, modules]
  end.to_h

  return ini_modules.merge(hub_modules) do |_version, ini_version_modules, json_version_modules|
    (ini_version_modules + json_version_modules).uniq(&:id)
  end
end
module_from_ini_data(module_key, entries, url_root, os) click to toggle source
# File lib/u3d/unity_module.rb, line 108
def module_from_ini_data(module_key, entries, url_root, os)
  url = entries['url']
  url = url_root + url unless /^http/ =~ url

  UnityModule.new(
    id: module_key,
    name: entries['title'],
    description: entries['description'],
    url: url,
    download_size: entries['size'],
    installed_size: entries['installedsize'],
    checksum: entries['md5'],
    command: entries['cmd'],
    depends_on: entries['sync'],
    os: os
  )
end
module_from_json_data(entries, os) click to toggle source
# File lib/u3d/unity_module.rb, line 126
def module_from_json_data(entries, os)
  UnityModule.new(
    id: entries['id'],
    name: entries['name'],
    description: entries['description'],
    url: entries['downloadUrl'],
    download_size: entries['downloadSize'],
    installed_size: entries['installedSize'],
    checksum: entries['checksum'],
    destination: entries['destination'],
    rename_from: entries['renameFrom'],
    rename_to: entries['renameTo'],
    command: entries['cmd'],
    depends_on: entries['sync'],
    os: os
  )
end

Public Instance Methods

depends_on?(other) click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/u3d/unity_module.rb, line 54
def depends_on?(other)
  return true if other.id == 'unity'
  return false unless depends_on

  other.id == depends_on || other.name == depends_on
end