discourse/lib/archetype.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

48 lines
707 B
Ruby

# frozen_string_literal: true
class Archetype
include ActiveModel::Serialization
attr_accessor :id, :options
def initialize(id, options)
@id = id
@options = options
end
def attributes
{
id: @id,
options: @options
}
end
def self.default
'regular'
end
def self.private_message
'private_message'
end
def self.banner
'banner'
end
def self.list
return [] unless @archetypes.present?
@archetypes.values
end
def self.register(name, options = {})
@archetypes ||= {}
@archetypes[name] = Archetype.new(name, options)
end
# default archetypes
register 'regular'
register 'private_message'
register 'banner'
end