0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
discourse-custom-wizard/lib/custom_wizard/log.rb

40 Zeilen
841 B
Ruby

2020-04-15 02:46:44 +02:00
class CustomWizard::Log
include ActiveModel::Serialization
attr_accessor :message, :date
PAGE_LIMIT = 100
def initialize(attrs)
@message = attrs['message']
@date = attrs['date']
end
def self.create(message)
log_id = SecureRandom.hex(12)
2020-04-15 04:34:39 +02:00
PluginStore.set('custom_wizard_log',
log_id.to_s,
2020-04-15 02:46:44 +02:00
{
date: Time.now,
message: message
}
)
end
def self.list_query
PluginStoreRow.where("
2020-04-15 04:34:39 +02:00
plugin_name = 'custom_wizard_log' AND
2020-04-15 02:46:44 +02:00
(value::json->'date') IS NOT NULL
").order("value::json->>'date' DESC")
end
2020-11-03 01:24:20 +01:00
def self.list(page = 0, limit = nil)
limit = limit.to_i > 0 ? limit.to_i : PAGE_LIMIT
page = page.to_i
self.list_query.limit(limit)
.offset(page * limit)
2020-04-15 02:46:44 +02:00
.map { |r| self.new(JSON.parse(r.value)) }
end
end