mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
44 lines
927 B
Crystal
44 lines
927 B
Crystal
module Ameba
|
|
enum Severity
|
|
Error
|
|
Warning
|
|
Refactoring
|
|
|
|
def self.default
|
|
Refactoring
|
|
end
|
|
|
|
def self.from_name(name : String)
|
|
case name.downcase
|
|
when "error"
|
|
Error
|
|
when "warning"
|
|
Warning
|
|
when "refactoring"
|
|
Refactoring
|
|
else
|
|
raise "Incorrect severity name #{name}. Try one of #{Severity.values}"
|
|
end
|
|
end
|
|
end
|
|
|
|
class SeverityYamlConverter
|
|
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
|
|
unless node.is_a?(YAML::Nodes::Scalar)
|
|
raise "Severity must be a scalar, not #{node.class}"
|
|
end
|
|
|
|
case value = node.value
|
|
when String then Severity.from_name(value)
|
|
when Nil then nil
|
|
else
|
|
raise "Incorrect severity: #{value}"
|
|
end
|
|
end
|
|
|
|
def self.to_yaml(value : Severity, yaml : YAML::Nodes::Builder)
|
|
yaml.scalar value.to_s
|
|
end
|
|
end
|
|
end
|