Module: Shared::IsDwcOccurrence

Extended by:
ActiveSupport::Concern
Included in:
AssertedDistribution, CollectionObject
Defined in:
app/models/concerns/shared/is_dwc_occurrence.rb

Overview

Shared code for data classes that can be serialized as DwcOccurrence records

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#dwc_occurrence_attribute_valuesArray

Returns an array of the values presently computed for this occurrence.

Returns:

  • (Array)

    an array of the values presently computed for this occurrence



70
71
72
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 70

def dwc_occurrence_attribute_values
  [id, dwc_occurrence.id] + self.class.dwc_attribute_vector[2..-1].collect{|a| a.name}.collect{|f| dwc_occurrence.send(f) }
end

#dwc_occurrence_attributesObject



57
58
59
60
61
62
63
64
65
66
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 57

def dwc_occurrence_attributes
  a = {}
  self.class::DWC_OCCURRENCE_MAP.each do |k,v|
    a[k] = send(v)
  end
  a[:project_id] = project_id
  a[:created_by_id] = created_by_id
  a[:updated_by_id] = updated_by_id
  a
end

#get_dwc_occurrenceDwcOccurrence

Returns does not rebuild if exists.

Returns:



76
77
78
79
80
81
82
83
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 76

def get_dwc_occurrence
  # TODO: why are extra queries fired if this is fired?
  if dwc_occurrence_persisted?
    dwc_occurrence
  else
    set_dwc_occurrence
  end
end

#set_dwc_occurrenceDwcOccurrence

Returns always touches the database.

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/concerns/shared/is_dwc_occurrence.rb', line 37

def set_dwc_occurrence
  retried = false
  begin
    if dwc_occurrence_persisted?
      dwc_occurrence.update_columns(dwc_occurrence_attributes)
    else
      create_dwc_occurrence!(dwc_occurrence_attributes)
    end
  rescue ActiveRecord::ActiveRecordError
    unless retried
      retried = true
      dwc_occurrence&.reload
      retry
    else
      raise
    end
  end
  dwc_occurrence
end