Method: OpenC3::Model#create
- Defined in:
- lib/openc3/models/model.rb
#create(update: false, force: false, queued: false, isoformat: false) ⇒ Object
Update the Redis hash at primary_key and set the field “name” to the JSON generated via calling as_json
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/openc3/models/model.rb', line 142 def create(update: false, force: false, queued: false, isoformat: false) unless force existing = self.class.store.hget(@primary_key, @name) if existing raise "#{@primary_key}:#{@name} already exists at create" unless update else raise "#{@primary_key}:#{@name} doesn't exist at update" if update end end if isoformat @updated_at = Time.now.utc.iso8601 else @updated_at = Time.now.utc.to_nsec_from_epoch end if queued write_store = self.class.store_queued else write_store = self.class.store end write_store.hset(@primary_key, @name, JSON.generate(self.as_json(:allow_nan => true), :allow_nan => true)) end |