class Logux::Model::Updater

Public Class Methods

new(model:, attributes:, logux_order: Logux.generate_action_id) click to toggle source
# File lib/logux/model/updater.rb, line 6
def initialize(model:, attributes:, logux_order: Logux.generate_action_id)
  @model = model
  @logux_order = logux_order
  @attributes = attributes
end

Public Instance Methods

updated_attributes() click to toggle source
# File lib/logux/model/updater.rb, line 12
def updated_attributes
  newer_updates.merge(logux_fields_updated_at: fields_updated_at)
end

Private Instance Methods

fields_updated_at() click to toggle source
# File lib/logux/model/updater.rb, line 18
def fields_updated_at
  @fields_updated_at ||=
    newer_updates.slice(*tracked_fields)
                 .keys
                 .reduce(@model.logux_fields_updated_at) do |acc, attr|
                   acc.merge(attr => @logux_order)
                 end
end
newer_updates() click to toggle source
# File lib/logux/model/updater.rb, line 27
def newer_updates
  @newer_updates ||= @attributes.reject do |attr, _|
    field_updated_at = @model.logux.updated_at(attr)
    field_updated_at && field_updated_at > @logux_order
  end
end
tracked_fields() click to toggle source
# File lib/logux/model/updater.rb, line 34
def tracked_fields
  @model.class.logux_crdt_mapped_attributes
end