Try to fetch gem and download its if it's possible, and
 build and install indicies.

 @param [String] resource
 @return [Indexer]
502863
def fetch_gem(resource)
      return unless Utils.configuration.fetch_gem
      name = File.basename(resource)
      result = name.match(URI_REGEXP)
      return unless result

      gem_name, gem_version, gem_platform, gem_type = result.captures
      return unless gem_name && gem_version

      begin
        gem = Utils.stored_gem(gem_name, gem_version, gem_platform)
        gem.gemspec = true if gem_type == GEMSPEC_TYPE

        # rubocop:disable Metrics/LineLength
        return if Utils.gems_fetcher.gem_exists?(gem.filename(gem_version)) && gem_type == GEM_TYPE
        return if Utils.gems_fetcher.gemspec_exists?(gem.gemspec_filename(gem_version)) && gem_type == GEMSPEC_TYPE
        # rubocop:enable Metrics/LineLength

        Utils.logger
             .info("Try to download #{gem_name} with version #{gem_version}")
        Utils.gems_fetcher.source.gems.clear
        Utils.gems_fetcher.source.gems.push(gem)
        Utils.gems_fetcher.fetch

        update_indexes if Utils.configuration.update_on_fetch
      rescue StandardError => e
        Utils.logger.error(e)
      end
    end
446796
def uri_from_other_sources
      uri = nil
      source.remotes.each do |remote|
        break if uri

        uri = case remote.host
              when 'rubygems.org' then next # already checked
              when 'rails-assets.org'
                uri_from_railsassets
              else
                Bundler.ui.error "Source #{remote} is not supported, ' \
                  'feel free to open a PR or an issue on https://github.com/MaximeD/gem_updater"
              end
      end

      uri
    end
1113226
def fetch_gem(gem, version)
      filename = gem.filename(version)
      satisfied = if gem.only_latest?
                    true
                  else
                    gem.requirement.satisfied_by?(version)
                  end
      name = gem.name

      if gem_exists?(filename) || ignore_gem?(name, version, gem.platform) ||
         !satisfied
        Utils.logger.debug("Skipping #{filename}")
        return
      end

      Utils.configuration.ignore_gem(gem.name, version, gem.platform)
      Utils.logger.info("Fetching #{filename}")

      fetch_from_source(filename, gem, version)
    end
1103395
def get_resources(resources)
      # prefetch api resources, skip missing APIs
      resource_apis = apis(resources.map(&:apiVersion), prefetch_resources: true, skip_missing: true)

      # map each resource to excon request options, or nil if resource is not (yet) defined
      requests = resources.zip(resource_apis).map{ |resource, api_client|
        next nil unless api_client.api_resources?

        resource_client = api_client.client_for_resource(resource)

        {
          method: 'GET',
          path: resource_client.path(resource.metadata.name, namespace: resource.metadata.namespace),
          response_class: resource_client.resource_class
        }
      }

      # map non-nil requests to response objects, or nil for nil request options
      Util.compact_map(requests) { |reqs|
        @transport.requests(*reqs, skip_missing: true)
      }
    end
513018
def get(path: nil, headers: {}, query: {})
      execute(method: :get, path: path, query: query, headers: headers)
    end
726520
def call(env)
      # Create a method called domain which will return the current domain
      # name
      Rails.application.send :define_singleton_method, 'domain_name' do
        env['SERVER_NAME']
      end

      # Create `fetch_domain` method on `Rails.application`
      # only if it didn't already define.
      unless Rails.application.respond_to? :fetch_domain
        Rails.application.send :define_singleton_method, 'fetch_domain' do
          if defined? ActiveRecord
            Domain.find_by(nam: Rails.application.domain_name)
          elsif defined? Mongoid
            Site.where('domains.name' => Rails.application.domain_name).domains.first
          end
        end
      end

      Rails.application.send :define_singleton_method, 'site' do
        site = nil
        unless Rails.application.domain.nil?
          site = Rails.application.domain.site
        end
        site
      end

      Rails.application
      @app.call(env)
    end
1142439
def download_from_source(file)
      source_host = Gemirro.configuration.source.host
      Utils.logger.info("Download from source: #{file}")
      resp = Http.get("#{source_host}/#{File.basename(file)}")
      return unless resp.code == 200
      resp.body
    end
1258682
def get_resource(id_or_uri, opts = {})
      data, _status_code, _headers = get_resource_with_http_info(id_or_uri, opts)
      return data
    end
701599
def load_from(gemspec_path, pattern)
      Gem.refresh
      spec = Gem::Specification.load(gemspec_path)
      dependencies = spec.runtime_dependencies.concat(spec.development_dependencies)
      dependencies.each do |gem|
        gem_name = gem.name[pattern]
        next if gem_name.to_s.empty?
        register(gem_name, Plugin.new(gem_name, gem))
      end
      self
    end
713349
function fetchFromCache(options, opts, cb) {
  // look for existing cached resource
  if (indirFiles.length > 0) {
    var etag;
    var regexp = '^' + opts.prefix +
                 '([A-Za-z0-9]+={0,2})' + // base64 encoded
                 opts.suffix + '$';
    var regex = new RegExp(regexp);
    var i;
    for (i = 0; i < indirFiles.length; i++) {
      var file = regex.exec(indirFiles[i]);
      if (file) {
        etag = new Buffer(file[1], 'base64').toString();
        break;
      }
    }

    if (etag) {
      try {
        var headOpts = JSON.parse(JSON.stringify(options)); // clone options
        headOpts.headers = { 'If-None-Match': etag };
        request.head(headOpts, function(err, res, body) {
          if (err) {
            logger.error(err);
            cb();
            // not fatal; continue
          } else if (res.statusCode === 304) {
            var filename = path.join(opts.outdir, indirFiles[i]);
            fs.copy(path.join(opts.indir, indirFiles[i]),
                    filename,
                    { preserveTimestamps: true },
                    function(err) {
                      if (err) {
                        throw (err);
                      }
                      var body = decryptData(fs.readFileSync(filename));
                      logger.info('Using cached copy of %s', indirFiles[i]);
                      var result = {
                        file: filename,
                        contents: body };
                      cb(null, result);
                    });
          } else {
            cb();
          }
        });
      } catch (e) {
        logger.error(e);
        cb();
        // not fatal; continue
      }
    } else {
      cb();
    }
  } else {
    cb();
  }
}
1195814
def get(self, resource):
        
        prefix, path = resource.finder.get_cache_info(resource)
        if prefix is None:
            result = path
        else:
            result = os.path.join(self.base, self.prefix_to_dir(prefix), path)
            dirname = os.path.dirname(result)
            if not os.path.isdir(dirname):
                os.makedirs(dirname)
            if not os.path.exists(result):
                stale = True
            else:
                stale = self.is_stale(resource, path)
            if stale:
                # write the bytes of the resource to the cache location
                with open(result, 'wb') as f:
                    f.write(resource.bytes)
        return result
1129387
def available_gems
      return [] unless gemfile_path
      dsl = Bundler::Dsl.evaluate(gemfile_path, nil, true)
      return dsl.dependencies.map(&:name)
    end
582353
def build_indicies
      specs = *map_gems_to_specs(gem_file_list)
      specs.select! { |s| s.class == ::Gem::Specification }
      ::Gem::Specification.dirs = []
      ::Gem::Specification.all = specs

      if ::Gem::VERSION >= '2.5.0'
        build_marshal_gemspecs specs
        build_modern_indices specs if @build_modern
        compress_indices
      else
        build_marshal_gemspecs
        build_modern_indicies if @build_modern
        compress_indicies
      end
    end
375851
def filename(gem_version = nil)
      gem_version ||= version.to_s
      n = [name, gem_version]
      n.push(@platform) if @platform != 'ruby'
      "#{n.join('-')}.gem"
    end
450232
def decorate(resource)
      return resource if resource.is_a? ResourceDecorator
      return resource.map { |item| decorate item } if resource.respond_to? :map
      decorator = Map.resource_decorator_map resource.class, controller_to_get(:application_decorator)
      decorator ? decorator.new(resource) : resource
    end
294461
def _resource_index(self, resource):
        
        datasource = self.get_datasource(resource)
        indexes = self._resource_config(resource, 'INDEXES') or {}
        default_index = self._resource_config(resource, 'INDEX')
        return indexes.get(datasource[0], default_index)
611153
def resource_index
      if self.class.included_modules.include? APPI::FiltersResources
        apply_filter_params resource_class.all
      else
        resource_class.all
      end
    end