discourse/lib/archetype.rb

46 lines
676 B
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
class Archetype
include ActiveModel::Serialization
attr_accessor :id, :options
def initialize(id, options)
@id = id
2013-02-25 11:42:20 -05:00
@options = options
2013-02-05 14:16:51 -05:00
end
def attributes
2014-06-16 10:17:27 -04:00
{
id: @id,
options: @options
}
2013-02-05 14:16:51 -05:00
end
def self.default
2013-02-25 11:42:20 -05:00
'regular'
2013-02-05 14:16:51 -05:00
end
def self.private_message
'private_message'
end
2014-06-16 10:17:27 -04:00
def self.banner
'banner'
end
2013-02-05 14:16:51 -05:00
def self.list
return [] unless @archetypes.present?
@archetypes.values
end
2017-07-27 21:20:09 -04:00
def self.register(name, options = {})
2013-02-05 14:16:51 -05:00
@archetypes ||= {}
@archetypes[name] = Archetype.new(name, options)
end
2014-06-16 10:17:27 -04:00
# default archetypes
2013-02-05 14:16:51 -05:00
register 'regular'
register 'private_message'
2014-06-16 10:17:27 -04:00
register 'banner'
2013-02-05 14:16:51 -05:00
end