renovate/lib/modules/datasource/rubygems/index.ts
Rhys Arkins 143c9a6751 refactor: rename lookupName -> packageName (#14494)
Renames `lookupName` to be `packageName`.

BREAKING CHANGE: Use `packageName` instead of `lookupName` if interacting with Renovate datasources directly.
2022-03-04 09:04:02 +01:00

49 lines
1.5 KiB
TypeScript

import { cache } from '../../../util/cache/package/decorator';
import { parseUrl } from '../../../util/url';
import * as rubyVersioning from '../../versioning/ruby';
import { Datasource } from '../datasource';
import type { GetReleasesConfig, ReleaseResult } from '../types';
import { InternalRubyGemsDatasource } from './get';
import { RubyGemsOrgDatasource } from './get-rubygems-org';
export class RubyGemsDatasource extends Datasource {
static readonly id = 'rubygems';
constructor() {
super(RubyGemsDatasource.id);
this.rubyGemsOrgDatasource = new RubyGemsOrgDatasource(
RubyGemsDatasource.id
);
this.internalRubyGemsDatasource = new InternalRubyGemsDatasource(
RubyGemsDatasource.id
);
}
override readonly defaultRegistryUrls = ['https://rubygems.org'];
override readonly defaultVersioning = rubyVersioning.id;
override readonly registryStrategy = 'hunt';
private readonly rubyGemsOrgDatasource: RubyGemsOrgDatasource;
private readonly internalRubyGemsDatasource: InternalRubyGemsDatasource;
@cache({
namespace: `datasource-${RubyGemsDatasource.id}`,
key: ({ registryUrl, packageName }: GetReleasesConfig) =>
`${registryUrl}/${packageName}`,
})
getReleases({
packageName,
registryUrl,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
if (parseUrl(registryUrl)?.hostname === 'rubygems.org') {
return this.rubyGemsOrgDatasource.getReleases({ packageName });
}
return this.internalRubyGemsDatasource.getReleases({
packageName,
registryUrl,
});
}
}