Class: OpenC3::ConfigTopic
- Defined in:
- lib/openc3/topics/config_topic.rb
Constant Summary collapse
- PRIMARY_KEY =
"__CONFIG"
Class Method Summary collapse
- .read(offset = nil, count: 100, scope:) ⇒ Object
-
.write(config, scope:) ⇒ Object
Write a configuration change to the topic.
Methods inherited from Topic
clear_topics, get_cnt, method_missing
Class Method Details
.read(offset = nil, count: 100, scope:) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/openc3/topics/config_topic.rb', line 48 def self.read(offset = nil, count: 100, scope:) topic = "#{scope}#{PRIMARY_KEY}" if offset result = Topic.read_topics([topic], [offset], nil, count) if result.empty? [] # We want to return an empty array rather than an empty hash else # result is a hash with the topic key followed by an array of results # This returns just the array of arrays [[offset, hash], [offset, hash], ...] result[topic] end else result = Topic.(topic) return [result] if result return [] end end |
.write(config, scope:) ⇒ Object
Write a configuration change to the topic
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/openc3/topics/config_topic.rb', line 31 def self.write(config, scope:) unless config.keys.include?(:kind) raise "ConfigTopic error, required key kind: not given" end unless ['created', 'deleted'].include?(config[:kind]) raise "ConfigTopic error unknown kind: #{config[:kind]}" end unless config.keys.include?(:name) raise "ConfigTopic error, required key name: not given" end unless config.keys.include?(:type) raise "ConfigTopic error, required key type: not given" end # Limit the configuration topics to 1000 entries Topic.write_topic("#{scope}#{PRIMARY_KEY}", config, '*', 1000) end |