Module: Metanorma::Release::PlatformFactory
- Defined in:
- lib/metanorma/release/platform_factory.rb
Defined Under Namespace
Classes: NullManifestReader, StaticDiscoverer
Constant Summary
collapse
- PUBLISHER_REGISTRY =
{
'null' => ->(_opts) { Platform::Null::Publisher.new },
'local' => ->(opts) { Platform::Local::Publisher.new(output_dir: opts[:output_dir]) }
}.freeze
- AGGREGATION_REGISTRY =
{
'local' => lambda { |opts, _token|
path = opts[:source].sub('local:', '')
{
discoverer: Platform::Local::DirectoryDiscoverer.new(base_path: path),
fetcher: Platform::Local::Fetcher.new(base_path: path)
}
}
}.freeze
Class Method Summary
collapse
Class Method Details
.build_aggregation_adapters(options) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/metanorma/release/platform_factory.rb', line 28
def self.build_aggregation_adapters(options)
source = options[:source]
if source.start_with?('local:')
adapters = AGGREGATION_REGISTRY['local'].call(options, options[:token])
adapters[:manifest_reader] = NullManifestReader.new
return adapters
end
require 'octokit'
client = build_github_client(options[:token])
discoverer = if options[:repos]
repos = options[:repos].map { |r| RepoRef.from_string(r) }
StaticDiscoverer.new(repos: repos)
else
Platform::GitHub::TopicDiscoverer.new(
client: client, organizations: options[:organizations], topic: options[:topic]
)
end
{
discoverer: discoverer,
fetcher: Platform::GitHub::ReleaseFetcher.new(client: client),
manifest_reader: Platform::GitHub::ManifestReader.new(client: client)
}
end
|
.build_github_client(token) ⇒ Object
55
56
57
58
|
# File 'lib/metanorma/release/platform_factory.rb', line 55
def self.build_github_client(token)
require 'octokit'
token ? Octokit::Client.new(access_token: token) : Octokit::Client.new
end
|
.build_publisher(platform, options) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/metanorma/release/platform_factory.rb', line 21
def self.build_publisher(platform, options)
factory = PUBLISHER_REGISTRY[platform]
raise ArgumentError, "Unknown platform: #{platform}. Available: #{PUBLISHER_REGISTRY.keys.join(', ')}" unless factory
factory.call(options)
end
|