mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +08:00
7c3a29c9d6
* Updates GitHub Actions * Switches from `bundler/inline` to an optional group in the `Gemfile` because the previous solution didn't work well with rspec * Adds the converter framework and tests * Allows loading private converters (see README) * Switches from multiple CLI tools to a single CLI * Makes DB connections reusable and adds a new abstraction for the `IntermediateDB` * `IntermediateDB` acts as an interface for IPC calls when a converter steps runs in parallel (forks). Only the main process writes to the DB. * Includes a simple example implementation of a converter for now.
46 lines
1.3 KiB
Ruby
46 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Migrations
|
|
module Converters
|
|
def self.all
|
|
@all_converters ||=
|
|
begin
|
|
base_path = File.join(::Migrations.root_path, "lib", "converters", "base")
|
|
core_paths = Dir[File.join(::Migrations.root_path, "lib", "converters", "*")]
|
|
private_paths = Dir[File.join(::Migrations.root_path, "private", "converters", "*")]
|
|
all_paths = core_paths - [base_path] + private_paths
|
|
|
|
all_paths.each_with_object({}) do |path, hash|
|
|
next unless File.directory?(path)
|
|
|
|
name = File.basename(path).downcase
|
|
existing_path = hash[name]
|
|
|
|
raise <<~MSG if existing_path
|
|
Duplicate converter name found: #{name}
|
|
* #{existing_path}
|
|
* #{path}
|
|
MSG
|
|
|
|
hash[name] = path
|
|
end
|
|
end
|
|
end
|
|
|
|
def self.names
|
|
self.all.keys.sort
|
|
end
|
|
|
|
def self.path_of(converter_name)
|
|
converter_name = converter_name.downcase
|
|
path = self.all[converter_name]
|
|
raise "Could not find a converter named '#{converter_name}'" unless path
|
|
path
|
|
end
|
|
|
|
def self.default_settings_path(converter_name)
|
|
File.join(path_of(converter_name), "settings.yml")
|
|
end
|
|
end
|
|
end
|