2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
class Archetype
|
|
|
|
include ActiveModel::Serialization
|
|
|
|
|
|
|
|
attr_accessor :id, :options
|
|
|
|
|
|
|
|
def initialize(id, options)
|
|
|
|
@id = id
|
2013-02-26 00:42:20 +08:00
|
|
|
@options = options
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def attributes
|
2014-06-16 22:17:27 +08:00
|
|
|
{ id: @id, options: @options }
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.default
|
2013-02-26 00:42:20 +08:00
|
|
|
"regular"
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.private_message
|
|
|
|
"private_message"
|
|
|
|
end
|
|
|
|
|
2014-06-16 22:17:27 +08:00
|
|
|
def self.banner
|
|
|
|
"banner"
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
def self.list
|
2024-05-27 18:27:13 +08:00
|
|
|
return [] if @archetypes.blank?
|
2013-02-06 03:16:51 +08:00
|
|
|
@archetypes.values
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.register(name, options = {})
|
|
|
|
@archetypes ||= {}
|
|
|
|
@archetypes[name] = Archetype.new(name, options)
|
|
|
|
end
|
|
|
|
|
2024-05-24 22:15:53 +08:00
|
|
|
def self.deregister(name)
|
|
|
|
@archetypes ||= {}
|
|
|
|
@archetypes.delete(name)
|
|
|
|
end
|
|
|
|
|
2014-06-16 22:17:27 +08:00
|
|
|
# default archetypes
|
2013-02-06 03:16:51 +08:00
|
|
|
register "regular"
|
|
|
|
register "private_message"
|
2014-06-16 22:17:27 +08:00
|
|
|
register "banner"
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|