REFACTOR: Instance methods added to 'PluginStore' model for easy access (#5315)
This commit is contained in:
parent
c025fcffa5
commit
cbc0afb399
|
@ -1,5 +1,23 @@
|
||||||
# API to wrap up plugin store rows
|
# API to wrap up plugin store rows
|
||||||
class PluginStore
|
class PluginStore
|
||||||
|
attr_reader :plugin_name
|
||||||
|
|
||||||
|
def initialize(plugin_name)
|
||||||
|
@plugin_name = plugin_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(key)
|
||||||
|
self.class.get(plugin_name, key)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set(key, value)
|
||||||
|
self.class.set(plugin_name, key, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove(key)
|
||||||
|
self.class.remove(plugin_name, key)
|
||||||
|
end
|
||||||
|
|
||||||
def self.get(plugin_name, key)
|
def self.get(plugin_name, key)
|
||||||
if row = PluginStoreRow.find_by(plugin_name: plugin_name, key: key)
|
if row = PluginStoreRow.find_by(plugin_name: plugin_name, key: key)
|
||||||
cast_value(row.type_name, row.value)
|
cast_value(row.type_name, row.value)
|
||||||
|
|
|
@ -2,16 +2,21 @@ require "rails_helper"
|
||||||
require_dependency "plugin_store"
|
require_dependency "plugin_store"
|
||||||
|
|
||||||
describe PluginStore do
|
describe PluginStore do
|
||||||
|
let(:store) { PluginStore.new("my_plugin_2") }
|
||||||
|
|
||||||
def set(k, v)
|
def set(k, v)
|
||||||
PluginStore.set("my_plugin", k, v)
|
PluginStore.set("my_plugin", k, v)
|
||||||
|
store.set(k, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(k)
|
def get(k)
|
||||||
PluginStore.get("my_plugin", k)
|
value = PluginStore.get("my_plugin", k)
|
||||||
|
value == store.get(k) ? value : "values mismatch"
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_row(k)
|
def remove_row(k)
|
||||||
PluginStore.remove("my_plugin", k)
|
PluginStore.remove("my_plugin", k)
|
||||||
|
store.remove(k)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "sets strings correctly" do
|
it "sets strings correctly" do
|
||||||
|
|
Loading…
Reference in New Issue