Class: ViewModel::ActiveRecord::AbstractCollectionUpdate::Functional
- Inherits:
-
Object
- Object
- ViewModel::ActiveRecord::AbstractCollectionUpdate::Functional
- Defined in:
- lib/view_model/active_record/update_data.rb
Overview
Wraps an ordered list of FunctionalUpdates, each of whose ‘contents` are either UpdateData for nested associations or references for referenced associations.
Direct Known Subclasses
OwnedCollectionUpdate::Functional, ReferencedCollectionUpdate::Functional
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
Instance Method Summary collapse
- #check_for_duplicates!(update_context, blame) ⇒ Object
- #contents ⇒ Object
-
#initialize(actions) ⇒ Functional
constructor
A new instance of Functional.
- #removed_vm_refs ⇒ Object
-
#used_vm_refs(_update_context) ⇒ Object
Resolve ViewModel::References used in the update’s contents, whether by reference or value.
- #vm_references(update_context) ⇒ Object
Constructor Details
#initialize(actions) ⇒ Functional
Returns a new instance of Functional.
73 74 75 |
# File 'lib/view_model/active_record/update_data.rb', line 73 def initialize(actions) @actions = actions end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
71 72 73 |
# File 'lib/view_model/active_record/update_data.rb', line 71 def actions @actions end |
Instance Method Details
#check_for_duplicates!(update_context, blame) ⇒ Object
101 102 103 104 105 106 107 |
# 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 ⇒ Object
77 78 79 80 81 82 |
# 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 ⇒ Object
94 95 96 97 98 99 |
# 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) ⇒ Object
Resolve ViewModel::References used in the update’s contents, whether by reference or value.
90 91 92 |
# 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) ⇒ Object
84 85 86 |
# 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 |