Class: U3d::UnityVersions::VersionsFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/u3d/unity_versions.rb

REGEX: expressions to interpret data collapse

REGEX: expressions to interpret data collapse

Constructor Details

#initialize(pattern:) ⇒ VersionsFetcher

Returns a new instance of VersionsFetcher.



260
261
262
263
# File 'lib/u3d/unity_versions.rb', line 260

def initialize(pattern:)
  @versions = {}
  @patterns = pattern.is_a?(Array) ? pattern : [pattern]
end

Instance Attribute Details

#versionsObject

Returns the value of attribute versions.



258
259
260
# File 'lib/u3d/unity_versions.rb', line 258

def versions
  @versions
end

Instance Method Details

#fetch_all_channelsObject



292
293
294
295
296
297
298
299
# File 'lib/u3d/unity_versions.rb', line 292

def fetch_all_channels
  fetch_some('lts', UNITY_LTSES)
  fetch_some('stable', UNITY_DOWNLOADS)
  fetch_some('patch', UNITY_PATCHES)
  # This does not work any longer
  # fetch_some('beta', UNITY_BETAS)
  @versions
end

#fetch_json(os) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/u3d/unity_versions.rb', line 277

def fetch_json(os)
  UI.message 'Loading Unity latest releases'
  url = UnityVersions.json_url_for(os)
  latest = UnityVersions.fetch_from_json(url, UNITY_LATEST_JSON)

  UI.success "Found #{latest.count} latest releases."

  @versions.merge!(latest) do |key, oldval, newval|
    UI.important "Unity version #{key} already fetched, replacing #{oldval} with #{newval}" if newval != oldval
    newval
  end

  @versions
end

#fetch_some(type, url) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/u3d/unity_versions.rb', line 265

def fetch_some(type, url)
  UI.message "Loading Unity #{type} releases"
  total = {}
  @patterns.each do |pattern|
    current = UnityVersions.fetch_version_paged(url, pattern)
    current = UnityVersions.fetch_version(url, pattern) if current.empty?
    total.merge!(current)
  end
  UI.success "Found #{total.count} #{type} releases."
  @versions.merge!(total)
end