Class: OpenC3::PluginStoreModel
- Inherits:
-
Model
show all
- Defined in:
- lib/openc3/models/plugin_store_model.rb
Constant Summary
collapse
- PRIMARY_KEY =
'openc3_plugin_store'
Instance Attribute Summary
Attributes inherited from Model
#name, #plugin, #scope, #updated_at
Class Method Summary
collapse
Methods inherited from Model
#as_json, #check_disable_erb, #create, #deploy, #destroy, #destroyed?, filter, find_all_by_plugin, from_json, get, get_all_models, get_model, handle_config, #initialize, names, store, store_queued, #undeploy, #update
Constructor Details
This class inherits a constructor from OpenC3::Model
Class Method Details
30
31
32
|
# File 'lib/openc3/models/plugin_store_model.rb', line 30
def self.all()
Store.get(PRIMARY_KEY)
end
|
.ensure_exists ⇒ Object
65
66
67
68
|
# File 'lib/openc3/models/plugin_store_model.rb', line 65
def self.ensure_exists
plugins = self.all()
self.update() if plugins.nil? or plugins.length.zero? or plugins[0]['error']
end
|
.get_by_id(id) ⇒ Object
43
44
45
46
|
# File 'lib/openc3/models/plugin_store_model.rb', line 43
def self.get_by_id(id)
plugins = JSON.parse(all()) rescue []
plugins.find { |plugin| plugin["id"] == Integer(id) }
end
|
.plugin_store_error(message) ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/openc3/models/plugin_store_model.rb', line 34
def self.plugin_store_error(message)
Store.set(PRIMARY_KEY, [{
date: Time.now.utc.iso8601,
title: 'Plugin Store Error',
body: message,
error: true,
}].to_json)
end
|
.set(plugin_store_data) ⇒ Object
26
27
28
|
# File 'lib/openc3/models/plugin_store_model.rb', line 26
def self.set(plugin_store_data)
Store.set(PRIMARY_KEY, plugin_store_data)
end
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/openc3/models/plugin_store_model.rb', line 48
def self.update
setting = SettingModel.get(name: 'store_url', scope: 'DEFAULT')
store_url = setting['data'] if setting
store_url = 'https://store.openc3.com' if store_url.nil? or store_url.strip.empty?
conn = Faraday.new(
url: store_url,
)
response = conn.get('/cosmos_plugins/json')
if response.success?
self.set(response.body)
else
self.plugin_store_error("Error contacting plugin store at #{store_url} (status: #{response.status})")
end
rescue Exception => e
self.plugin_store_error("Error contacting plugin store at #{store_url}. #{e.message})")
end
|