Module: Metanorma::Release::PlatformFactory
- Defined in:
- lib/metanorma/release/platform_factory.rb
Constant Summary collapse
- PUBLISHER_REGISTRY =
{ "null" => ->(_opts) { Platform::Null::Publisher.new }, "local" => ->(opts) { Platform::Local::Publisher.new(output_dir: opts[:output_dir]) }, }.dup
- 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), } }, "github" => lambda { |opts, token| require "octokit" client = build_github_client(token) discoverer = if opts[:repos] repos = opts[:repos].map { |r| RepoRef.from_string(r) } Platform::StaticDiscoverer.new(repos: repos) else Platform::GitHub::TopicDiscoverer.new( client: client, organizations: opts[:organizations], topic: opts[:topic], ) end download_cache = if opts[:cache_dir] File.join(opts[:cache_dir], "downloads") end { discoverer: discoverer, fetcher: Platform::GitHub::ReleaseFetcher.new(client: client, download_cache_dir: download_cache), manifest_reader: Platform::GitHub::ManifestReader.new(client: client), } }, }.dup
Class Method Summary collapse
- .build_aggregation_adapters(options) ⇒ Object
- .build_github_client(token) ⇒ Object
- .build_publisher(platform, options) ⇒ Object
- .register_aggregation(name, factory) ⇒ Object
- .register_publisher(name, factory) ⇒ Object
Class Method Details
.build_aggregation_adapters(options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/metanorma/release/platform_factory.rb', line 58 def self.build_aggregation_adapters() source = [:source] if source.start_with?("local:") adapters = AGGREGATION_REGISTRY["local"].call(, [:token]) adapters[:manifest_reader] = Platform::Null::ManifestReader.new return adapters end AGGREGATION_REGISTRY["github"].call(, [:token]) end |
.build_github_client(token) ⇒ Object
71 72 73 74 75 |
# File 'lib/metanorma/release/platform_factory.rb', line 71 def self.build_github_client(token) require "octokit" access_token = token || ENV.fetch("GITHUB_TOKEN", nil) access_token ? Octokit::Client.new(access_token: access_token) : Octokit::Client.new end |
.build_publisher(platform, options) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/metanorma/release/platform_factory.rb', line 48 def self.build_publisher(platform, ) factory = PUBLISHER_REGISTRY[platform] unless factory raise ArgumentError, "Unknown platform: #{platform}. Available: #{PUBLISHER_REGISTRY.keys.join(', ')}" end factory.call() end |
.register_aggregation(name, factory) ⇒ Object
81 82 83 |
# File 'lib/metanorma/release/platform_factory.rb', line 81 def self.register_aggregation(name, factory) AGGREGATION_REGISTRY[name] = factory end |
.register_publisher(name, factory) ⇒ Object
77 78 79 |
# File 'lib/metanorma/release/platform_factory.rb', line 77 def self.register_publisher(name, factory) PUBLISHER_REGISTRY[name] = factory end |