class ViewModel::ActiveRecord::AbstractCollectionUpdate::Functional

Wraps an ordered list of FunctionalUpdates, each of whose `contents` are either UpdateData for nested associations or references for referenced associations.

Attributes

actions[R]

Public Class Methods

new(actions) click to toggle source
# File lib/view_model/active_record/update_data.rb, line 73
def initialize(actions)
  @actions = actions
end

Public Instance Methods

check_for_duplicates!(update_context, blame) click to toggle source
# File lib/view_model/active_record/update_data.rb, line 101
def check_for_duplicates!(update_context, blame)
  duplicate_vm_refs = vm_references(update_context).duplicates
  if duplicate_vm_refs.present?
    formatted_invalid_ids = duplicate_vm_refs.keys.map(&:to_s).join(', ')
    raise ViewModel::DeserializationError::InvalidStructure.new("Duplicate functional update targets: [#{formatted_invalid_ids}]", blame)
  end
end
contents() click to toggle source
# File lib/view_model/active_record/update_data.rb, line 77
def contents
  actions.lazy
    .reject { |action| action.is_a?(FunctionalUpdate::Remove) }
    .flat_map(&:contents)
    .to_a
end
removed_vm_refs() click to toggle source
# File lib/view_model/active_record/update_data.rb, line 94
def removed_vm_refs
  actions.lazy
    .select { |action| action.is_a?(FunctionalUpdate::Remove) }
    .flat_map(&:removed_vm_refs)
    .to_a
end
used_vm_refs(_update_context) click to toggle source

Resolve ViewModel::References used in the update's contents, whether by reference or value.

# File lib/view_model/active_record/update_data.rb, line 90
def used_vm_refs(_update_context)
  raise RuntimeError.new('abstract method')
end
vm_references(update_context) click to toggle source
# File lib/view_model/active_record/update_data.rb, line 84
def vm_references(update_context)
  used_vm_refs(update_context) + removed_vm_refs
end