Class: OpenC3::MetricModel

Inherits:
EphemeralModel show all
Defined in:
lib/openc3/models/metric_model.rb

Constant Summary collapse

PRIMARY_KEY =
'__openc3__metric'.freeze

Instance Attribute Summary

Attributes inherited from Model

#name, #plugin, #scope, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EphemeralModel

store

Methods inherited from Model

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

Constructor Details

#initialize(name:, scope:, metric_name:, label_list:) ⇒ MetricModel

Returns a new instance of MetricModel.



47
48
49
50
51
# File 'lib/openc3/models/metric_model.rb', line 47

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

Class Method Details

.all(scope:) ⇒ Object



39
40
41
# File 'lib/openc3/models/metric_model.rb', line 39

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

.destroy(scope:, name:) ⇒ Object



43
44
45
# File 'lib/openc3/models/metric_model.rb', line 43

def self.destroy(scope:, name:)
  EphemeralStore.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



31
32
33
# File 'lib/openc3/models/metric_model.rb', line 31

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

.names(scope:) ⇒ Object



35
36
37
# File 'lib/openc3/models/metric_model.rb', line 35

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

Instance Method Details

#as_json(*a) ⇒ Object



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

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