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])
  },
}.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) }
                   StaticDiscoverer.new(repos: repos)
                 else
                   Platform::GitHub::TopicDiscoverer.new(
                     client: client, organizations: opts[:organizations], topic: opts[:topic],
                   )
                 end

    {
      discoverer: discoverer,
      fetcher: Platform::GitHub::ReleaseFetcher.new(client: client),
      manifest_reader: Platform::GitHub::ManifestReader.new(client: client),
    }
  },
}.dup

Class Method Summary collapse

Class Method Details

.build_aggregation_adapters(options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/metanorma/release/platform_factory.rb', line 52

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

  AGGREGATION_REGISTRY["github"].call(options, options[:token])
end

.build_github_client(token) ⇒ Object



65
66
67
68
# File 'lib/metanorma/release/platform_factory.rb', line 65

def self.build_github_client(token)
  require "octokit"
  token ? Octokit::Client.new(access_token: token) : Octokit::Client.new
end

.build_publisher(platform, options) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/metanorma/release/platform_factory.rb', line 42

def self.build_publisher(platform, options)
  factory = PUBLISHER_REGISTRY[platform]
  unless factory
    raise ArgumentError,
          "Unknown platform: #{platform}. Available: #{PUBLISHER_REGISTRY.keys.join(', ')}"
  end

  factory.call(options)
end

.register_aggregation(name, factory) ⇒ Object



74
75
76
# File 'lib/metanorma/release/platform_factory.rb', line 74

def self.register_aggregation(name, factory)
  AGGREGATION_REGISTRY[name] = factory
end

.register_publisher(name, factory) ⇒ Object



70
71
72
# File 'lib/metanorma/release/platform_factory.rb', line 70

def self.register_publisher(name, factory)
  PUBLISHER_REGISTRY[name] = factory
end