2020-12-22 09:53:41 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# SuperClass for models that are secured by chained footprints.
|
|
|
|
class Footprintable < ApplicationRecord
|
|
|
|
self.abstract_class = true
|
|
|
|
|
2020-12-21 17:37:58 +01:00
|
|
|
def self.columns_out_of_footprint
|
|
|
|
[]
|
|
|
|
end
|
2020-12-22 09:53:41 +01:00
|
|
|
|
2021-04-16 16:03:10 +02:00
|
|
|
def footprint_children
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def sort_on_field
|
|
|
|
'id'
|
|
|
|
end
|
|
|
|
|
2020-12-22 09:53:41 +01:00
|
|
|
def check_footprint
|
2021-04-16 16:03:10 +02:00
|
|
|
footprint_children.map(&:check_footprint).all? && footprint == compute_footprint
|
2020-12-22 09:53:41 +01:00
|
|
|
end
|
|
|
|
|
2021-04-16 16:03:10 +02:00
|
|
|
def chain_record
|
2020-12-22 09:53:41 +01:00
|
|
|
self.footprint = compute_footprint
|
|
|
|
save!
|
|
|
|
FootprintDebug.create!(
|
|
|
|
footprint: footprint,
|
2021-04-16 16:03:10 +02:00
|
|
|
data: FootprintService.footprint_data(self.class, self),
|
2020-12-22 09:53:41 +01:00
|
|
|
klass: self.class.name
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def debug_footprint
|
|
|
|
FootprintService.debug_footprint(self.class, self)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2021-04-16 16:03:10 +02:00
|
|
|
def compute_footprint
|
|
|
|
FootprintService.compute_footprint(self.class, self)
|
2020-12-22 09:53:41 +01:00
|
|
|
end
|
2020-12-21 17:37:58 +01:00
|
|
|
end
|