Class: OpenC3::EnvironmentModel

Inherits:
Model show all
Defined in:
lib/openc3/models/environment_model.rb

Constant Summary collapse

PRIMARY_KEY =
'__openc3__environment'.freeze

Instance Attribute Summary

Attributes inherited from Model

#name, #plugin, #scope, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#check_disable_erb, #create, #deploy, #destroy, #destroyed?, filter, find_all_by_plugin, from_json, get_all_models, get_model, handle_config, names, set, store, store_queued, #undeploy, #update

Constructor Details

#initialize(name:, scope:, key:, value:) ⇒ EnvironmentModel

Returns a new instance of EnvironmentModel.



46
47
48
49
50
# File 'lib/openc3/models/environment_model.rb', line 46

def initialize(name:, scope:, key:, value:)
  super("#{scope}#{PRIMARY_KEY}", name: name, scope: scope)
  @key = key
  @value = value
end

Class Method Details

.all(scope:) ⇒ Object



38
39
40
# File 'lib/openc3/models/environment_model.rb', line 38

def self.all(scope:)
  super("#{scope}#{PRIMARY_KEY}")
end

.destroy(scope:, name:) ⇒ Object



42
43
44
# File 'lib/openc3/models/environment_model.rb', line 42

def self.destroy(scope:, name:)
  Store.hdel("#{scope}#{PRIMARY_KEY}", name)
end

.get(name:, scope:) ⇒ Object

NOTE: The following three class methods are used by the ModelController and are reimplemented to enable various Model class methods to work



34
35
36
# File 'lib/openc3/models/environment_model.rb', line 34

def self.get(name:, scope:)
  super("#{scope}#{PRIMARY_KEY}", name: name)
end

Instance Method Details

#as_json(*a) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/openc3/models/environment_model.rb', line 52

def as_json(*a)
  {
    'name' => @name,
    'updated_at' => @updated_at,
    'key' => @key,
    'value' => @value
  }
end