Sha256: 532ae33ee6be57077a4ba3c30f5af745b02d356d794603c93ac37692677cfb0e

Contents?: true

Size: 792 Bytes

Versions: 3

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

# ImportDocument class
class ImportDocument < ApplicationRecord
  has_many :import_document_transitions, autosave: false, dependent: :destroy

  include Statesman::Adapters::ActiveRecordQueries[
    transition_class: ImportDocumentTransition,
    initial_state: :queued
  ]

  def state_machine
    @state_machine ||= ImportDocumentStateMachine.new(self, transition_class: ImportDocumentTransition)
  end

  def to_hash
    {
      friendlier_id: friendlier_id,
      title: title,
      json_attributes: nullify_empty_json_attributes,
      import_id: import_id
    }
  end

  def nullify_empty_json_attributes
    clean_hash = {}

    json_attributes.each do |key, value|
      clean_hash[key] = value.present? ? value : nil
    end

    clean_hash
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geoblacklight_admin-0.2.1 app/models/import_document.rb
geoblacklight_admin-0.1.0 app/models/import_document.rb
geoblacklight_admin-0.0.1 app/models/import_document.rb