"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RubyGemsDatasource = void 0;
const tslib_1 = require("tslib");
const error_messages_1 = require("../../../constants/error-messages");
const decorator_1 = require("../../../util/cache/package/decorator");
const url_1 = require("../../../util/url");
const rubyVersioning = tslib_1.__importStar(require("../../versioning/ruby"));
const datasource_1 = require("../datasource");
const get_1 = require("./get");
const versions_datasource_1 = require("./versions-datasource");
class RubyGemsDatasource extends datasource_1.Datasource {
    static id = 'rubygems';
    constructor() {
        super(RubyGemsDatasource.id);
        this.versionsDatasource = new versions_datasource_1.VersionsDatasource(RubyGemsDatasource.id);
        this.internalRubyGemsDatasource = new get_1.InternalRubyGemsDatasource(RubyGemsDatasource.id);
    }
    defaultRegistryUrls = ['https://rubygems.org'];
    defaultVersioning = rubyVersioning.id;
    registryStrategy = 'hunt';
    versionsDatasource;
    internalRubyGemsDatasource;
    async getReleases({ packageName, registryUrl, }) {
        // istanbul ignore if
        if (!registryUrl) {
            return null;
        }
        try {
            return await this.versionsDatasource.getReleases({
                packageName,
                registryUrl,
            });
        }
        catch (error) {
            if (error.message === error_messages_1.PAGE_NOT_FOUND_ERROR &&
                (0, url_1.parseUrl)(registryUrl)?.hostname !== 'rubygems.org') {
                return this.internalRubyGemsDatasource.getReleases({
                    packageName,
                    registryUrl,
                });
            }
            throw error;
        }
    }
}
tslib_1.__decorate([
    (0, decorator_1.cache)({
        namespace: `datasource-${RubyGemsDatasource.id}`,
        key: ({ registryUrl, packageName }) => 
        // TODO: types (#7154)
        /* eslint-disable @typescript-eslint/restrict-template-expressions */
        `${registryUrl}/${packageName}`,
    })
], RubyGemsDatasource.prototype, "getReleases", null);
exports.RubyGemsDatasource = RubyGemsDatasource;
//# sourceMappingURL=index.js.map