Sha256: 28d142058b8ec9f70d73a56a0a176f1f4bc79476bfc63172bdc210a695f403e3

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

# -*- coding: utf-8 -*-

module Gemirro
  ##
  # The Indexer class is responsible for downloading useful file directly
  # on the source host, such as specs-*.*.gz, marshal information, etc...
  #
  # @!attribute [r] files
  #  @return [Array]
  # @!attribute [r] quick_marshal_dir
  #  @return [String]
  # @!attribute [r] directory
  #  @return [String]
  # @!attribute [r] dest_directory
  #  @return [String]
  #
  class Indexer < ::Gem::Indexer
    attr_accessor :files, :quick_marshal_dir, :directory, :dest_directory

    ##
    # Generate indicies on the destination directory
    #
    # @return [Array]
    #
    def install_indicies
      verbose = ::Gem.configuration.really_verbose
      say "Downloading index into production dir #{@dest_directory}" if verbose

      files = @files
      files.delete @quick_marshal_dir if files.include? @quick_dir

      if files.include?(@quick_marshal_dir) && !files.include?(@quick_dir)
        files.delete @quick_marshal_dir
        dst_name = File.join(@dest_directory, @quick_marshal_dir_base)
        FileUtils.mkdir_p(File.dirname(dst_name), verbose: verbose)
        FileUtils.rm_rf(dst_name, verbose: verbose)
        FileUtils.mv(@quick_marshal_dir, dst_name,
                     verbose: verbose, force: true)
      end

      files = files.map do |path|
        path.sub(/^#{Regexp.escape @directory}\/?/, '')
      end

      files.each do |file|
        dst_name = File.join @dest_directory, file
        next if File.exist?(dst_name) &&
          (File.mtime(dst_name) >= Time.now - 360)

        resp = Http.get("#{Gemirro.configuration.source.host}/#{file}")
        next unless resp.code == 200
        MirrorFile.new(dst_name).write(resp.body)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gemirro-0.3.0 lib/gemirro/indexer.rb
gemirro-0.2.0 lib/gemirro/indexer.rb
gemirro-0.1.0 lib/gemirro/indexer.rb
gemirro-0.0.2 lib/gemirro/indexer.rb
gemirro-0.0.1 lib/gemirro/indexer.rb