Method: OpenC3::Model#create
- Defined in:
- lib/openc3/models/model.rb
#create(update: false, force: false) ⇒ Object
Update the Redis hash at primary_key and set the field “name” to the JSON generated via calling as_json
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/openc3/models/model.rb', line 137 def create(update: false, force: 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 @updated_at = Time.now.to_nsec_from_epoch self.class.store.hset(@primary_key, @name, JSON.generate(self.as_json(:allow_nan => true), :allow_nan => true)) end |