mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-07 19:28:28 +08:00
We didn't have support in the #problem constructor for multiple targets, forcing developers to manually construct a Problem instance. This involves a lot of details and is error prone. This PR supports passing an optional target argument to the constructor. This will be passed on to the translation_data method to generate the correct message as well.
32 lines
742 B
Ruby
32 lines
742 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ProblemCheck::Problem
|
|
PRIORITIES = %w[low high].freeze
|
|
|
|
attr_reader :message, :priority, :identifier, :target, :details
|
|
|
|
def initialize(message, priority: "low", identifier: nil, target: nil, details: {})
|
|
@message = message
|
|
@priority = PRIORITIES.include?(priority) ? priority : "low"
|
|
@identifier = identifier
|
|
@target = target
|
|
@details = details
|
|
end
|
|
|
|
def to_s
|
|
@message
|
|
end
|
|
|
|
def to_h
|
|
{ message:, priority:, identifier:, target: }
|
|
end
|
|
alias_method :attributes, :to_h
|
|
|
|
def self.from_h(h)
|
|
h = h.with_indifferent_access
|
|
|
|
return if h[:message].blank?
|
|
|
|
new(h[:message], priority: h[:priority], identifier: h[:identifier], target: h[:target])
|
|
end
|
|
end
|