Class: RecordLoader::RequestTypeLoader

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

Overview

Creates the specified request types if they are not present

Instance Method Summary collapse

Methods inherited from ApplicationRecordLoader

#wip_list

Instance Method Details

#create_or_update!(key, options) ⇒ Object



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

def create_or_update!(key, options)
  RequestType
    .create_with(filter_options(options))
    .find_or_create_by!(key:)
    .tap do |request_type|
      add_library_types(request_type, options.fetch('library_types', []))
      add_acceptable_purposes(request_type, options.fetch('acceptable_purposes', []))
    end
rescue StandardError => e
  raise StandardError, "Failed to create #{key} due to: #{e.message}"
end