app/models/esa/context.rb in event_sourced_accounting-0.2.2 vs app/models/esa/context.rb in event_sourced_accounting-0.2.3
- old
+ new
@@ -106,11 +106,11 @@
true
end
end
def update!(options = {})
- self.freshness = Time.zone.now
+ self.freshness = self.next_freshness_timestamp
ESA.configuration.context_checkers.each do |checker|
if checker.respond_to? :check
checker.check(self, options)
end
@@ -119,14 +119,22 @@
self.update_name
self.save if self.can_be_persisted?
end
def update_freshness_timestamp!
- self.freshness = Time.zone.now
+ self.freshness = self.next_freshness_timestamp
self.save if self.can_be_persisted?
end
+ def next_freshness_timestamp
+ if self.parent.present?
+ [self.freshness, self.parent.try(:freshness)].compact.max
+ else
+ Time.zone.now
+ end
+ end
+
def subcontext_namespaces
self.subcontexts.pluck(:namespace).compact.uniq
end
def effective_contexts
@@ -223,10 +231,10 @@
end
end
def parents_and_self
contexts = [self]
- while contexts.last.parent_id.present? and
+ while contexts.last.parent_id.present? and
not contexts.last.parent_id.in? contexts.map(&:id) and
contexts.count < 16 do
# found a valid parent
contexts << contexts.last.parent
end