Class: RecordLoader::TagGroupLoader

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

Overview

Creates the specified tag groups if they are not present

Instance Method Summary collapse

Instance Method Details

#create_or_update!(name, options) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/record_loader/tag_group_loader.rb', line 13

def create_or_update!(name, options)
  tags = options.delete('tags') || []

  TagGroup
    .create_with(options)
    .find_or_create_by!(name: name)
    .tap do |tag_group|
      tag_attributes = tags.map { |map_id, oligo| { map_id: map_id, oligo: oligo } }
      tag_group.tags.import(tag_attributes) if tag_group.tags.empty?
    end
end