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

Instance Method Details

#create_or_update!(key, options) ⇒ Object


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

def create_or_update!(key, options)
  creation_options = default_options.merge(options)
  acceptable_plate_purpose_names = creation_options.delete('acceptable_plate_purposes')
  creation_options['acceptable_plate_purposes'] =
    PlatePurpose.where(name: acceptable_plate_purpose_names) if acceptable_plate_purpose_names
  RequestType.create_with(creation_options).find_or_create_by!(key: key)
end

#default_optionsObject

Handles the default options not otherwise handled by the database defaults


21
22
23
# File 'lib/record_loader/request_type_loader.rb', line 21

def default_options
  { request_purpose: :standard, initial_state: 'pending' }
end