mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 05:09:20 +08:00
Ruby's compact module syntax (`module Migrations::Database::Schema::DSL`) breaks lexical constant lookup — `Module.nesting` only includes the innermost constant, so every cross-module reference must be fully qualified. In practice this means writing `Migrations::Database::Schema::Helpers` even when you're already inside `Migrations::Database::Schema`. Nested module definitions restore the full nesting chain, which brings several practical benefits: - **Less verbose code**: references like `Schema::Helpers`, `Database::IntermediateDB`, or `Converters::Base::ProgressStep` work without repeating the full path from root - **Easier to write new code**: contributors don't need to remember which prefixes are required — if you're inside the namespace, short names just work - **Fewer aliasing workarounds**: removes the need for constants like `MappingType = Migrations::Importer::MappingType` that existed solely to shorten references - **Standard Ruby style**: consistent with how most Ruby projects and gems structure their namespaces The diff is large but mechanical — no logic changes, just module wrapping and shortening references that the nesting now resolves. Generated code (intermediate_db models/enums) keeps fully qualified references like `Migrations::Database.format_*` since it must work regardless of the configured output namespace. - Convert 138 lib files from compact to nested module definitions - Remove now-redundant fully qualified prefixes and aliases - Update model and enum writers to generate nested modules with correct indentation - Regenerate all intermediate_db models and enums
46 lines
1.2 KiB
Ruby
46 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Migrations
|
|
module Converters
|
|
module Base
|
|
class StepTracker
|
|
attr_reader :stats
|
|
|
|
def initialize
|
|
@stats = StepStats.new
|
|
reset_stats!
|
|
end
|
|
|
|
def reset_stats!
|
|
@stats.progress = 1
|
|
@stats.warning_count = 0
|
|
@stats.error_count = 0
|
|
end
|
|
|
|
def progress=(value)
|
|
@stats.progress = value
|
|
end
|
|
|
|
def log_info(message, details: nil)
|
|
log(Database::IntermediateDB::LogEntry::INFO, message, details:)
|
|
end
|
|
|
|
def log_warning(message, exception: nil, details: nil)
|
|
@stats.warning_count += 1
|
|
log(Database::IntermediateDB::LogEntry::WARNING, message, exception:, details:)
|
|
end
|
|
|
|
def log_error(message, exception: nil, details: nil)
|
|
@stats.error_count += 1
|
|
log(Database::IntermediateDB::LogEntry::ERROR, message, exception:, details:)
|
|
end
|
|
|
|
private
|
|
|
|
def log(type, message, exception: nil, details: nil)
|
|
Database::IntermediateDB::LogEntry.create(type:, message:, exception:, details:)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|