Module: Arks

Included in:
ArchivalObject, Resource
Defined in:
backend/app/model/mixins/arks.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'backend/app/model/mixins/arks.rb', line 3

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#apply_nested_records(json, new_record = false) ⇒ Object

You’d think we’d put this in either create_from_json or update_from_json but if we did we’d miss out on having our new ARK being indexed by the realtime indexer via fire_update. So instead, we “hook” ourselves into apply_nested_records which conveniently happens before the fire_update.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'backend/app/model/mixins/arks.rb', line 11

def apply_nested_records(json, new_record = false)
  super

  return unless AppConfig[:arks_enabled]

  ark_name = {
    'current' => json['import_current_ark'],
    'previous' => ASUtils.wrap(json['import_previous_arks']),
  }

  if ark_name['current'] || !ark_name['previous'].empty?
    ArkName.update_for_record(self, ark_name)

    # If external ARKs are enabled, we now definitely have a current ARK.
    if ark_name['current'] && AppConfig[:arks_allow_external_arks]
      return
    end
  end

  ArkName.ensure_ark_for_record(self, json['external_ark_url'])
end