Sha256: e33630709eafea61246809b528119e6c8bd833bc3dd3f9187b78ac48597d602d
Contents?: true
Size: 1.26 KB
Versions: 13
Compression:
Stored size: 1.26 KB
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 data_hash = { friendlier_id: friendlier_id, title: title, json_attributes: nullify_empty_json_attributes, import_id: import_id } append_created_at(data_hash) append_updated_at(data_hash) 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 def append_created_at(data_hash) if data_hash[:json_attributes].has_key?("date_created_dtsi") data_hash[:created_at] = data_hash[:json_attributes]["date_created_dtsi"] end data_hash end def append_updated_at(data_hash) if data_hash[:json_attributes].has_key?("date_modified_dtsi") data_hash[:updated_at] = data_hash[:json_attributes]["date_modified_dtsi"] end data_hash end end
Version data entries
13 entries across 13 versions & 1 rubygems