2021-03-11 07:30:15 +01:00
|
|
|
# frozen_string_literal: true
|
2019-05-31 09:54:11 +02:00
|
|
|
class CustomWizard::Api
|
|
|
|
include ActiveModel::SerializerSupport
|
|
|
|
|
2024-10-16 13:52:03 +02:00
|
|
|
attr_accessor :name, :title
|
2019-05-31 09:54:11 +02:00
|
|
|
|
2021-03-11 07:30:15 +01:00
|
|
|
def initialize(name, data = {})
|
2019-06-02 12:54:31 +02:00
|
|
|
@name = name
|
2024-10-16 13:52:03 +02:00
|
|
|
data.each { |k, v| self.send "#{k}=", v if self.respond_to?(k) }
|
2019-06-02 12:54:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.set(name, data)
|
|
|
|
PluginStore.set("custom_wizard_api_#{name}", "metadata", data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get(name)
|
|
|
|
if data = PluginStore.get("custom_wizard_api_#{name}", "metadata")
|
|
|
|
self.new(name, data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.remove(name)
|
|
|
|
PluginStore.remove("custom_wizard_api_#{name}", "metadata")
|
2019-05-31 09:54:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.list
|
2024-10-16 13:52:03 +02:00
|
|
|
PluginStoreRow
|
|
|
|
.where("plugin_name LIKE 'custom_wizard_api_%' AND key = 'metadata'")
|
2019-05-31 09:54:11 +02:00
|
|
|
.map do |record|
|
2024-10-16 13:52:03 +02:00
|
|
|
self.new(record["plugin_name"].sub("custom_wizard_api_", ""), ::JSON.parse(record["value"]))
|
2019-05-31 09:54:11 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|