Class: RecordLoader::RobotPropertyLoader

Inherits:
ApplicationRecordLoader show all
Defined in:
lib/record_loader/robot_property_loader.rb

Overview

Creates the specified robot properties if they are not present

Instance Method Summary collapse

Instance Method Details

#create_or_update!(name, options) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/record_loader/robot_property_loader.rb', line 11

def create_or_update!(name, options)
  # find the robot by name
  r = Robot.find_by(name: name)
  return if r.blank?

  # find or create each property
  options['properties'].each do |property_options|
    property_options['robot_id'] = r.id
    RobotProperty.create_with(property_options).find_or_create_by!(robot_id: r.id, key: property_options['key'])
  end
end