Sha256: a490fde5bf4024e954519a92f715f4e8813911fd7852858e642dfd9e2734bae9

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

# -*- coding: utf-8 -*-
module Gemirro
  ##
  # The VersionsFetcher class is used for retrieving the file that contains all
  # registered Gems and their versions.
  #
  # @!attribute [r] source
  # @return [Source]
  #
  class VersionsFetcher
    attr_reader :source

    ##
    # @param [Source] source
    #
    def initialize(source)
      @source = source
    end

    ##
    # @return [Gemirro::VersionsFile]
    #
    def fetch
      VersionsFile.load(read_file(Configuration.versions_file),
                        read_file(Configuration.prerelease_versions_file, true))
    end

    ##
    # Read file if exists otherwise download its from source
    #
    # @param [String] file name
    # @param [TrueClass|FalseClass] prerelease Is prerelease or not
    #
    def read_file(file, prerelease = false)
      destination = Gemirro.configuration.destination
      file_dst = File.join(destination, file)
      unless File.exist?(file_dst)
        File.write(file_dst, @source.fetch_versions) unless prerelease
        File.write(file_dst, @source.fetch_prerelease_versions) if prerelease
      end

      File.read(file_dst)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gemirro-0.13.5 lib/gemirro/versions_fetcher.rb
gemirro-0.13.4 lib/gemirro/versions_fetcher.rb
gemirro-0.13.3 lib/gemirro/versions_fetcher.rb
gemirro-0.13.2 lib/gemirro/versions_fetcher.rb
gemirro-0.13.1 lib/gemirro/versions_fetcher.rb
gemirro-0.12.0 lib/gemirro/versions_fetcher.rb