Class: ViewModel::ActiveRecord::ReferencedCollectionUpdate::Parser

Inherits:
AbstractCollectionUpdate::Parser show all
Defined in:
lib/view_model/active_record/update_data.rb

Instance Method Summary collapse

Methods inherited from AbstractCollectionUpdate::Parser

#initialize, #parse

Constructor Details

This class inherits a constructor from ViewModel::ActiveRecord::AbstractCollectionUpdate::Parser

Instance Method Details

#append_action_schemaObject



347
348
349
# File 'lib/view_model/active_record/update_data.rb', line 347

def append_action_schema
  UpdateData::Schemas::REFERENCED_APPEND_ACTION
end

#functional_update_schemaObject



343
344
345
# File 'lib/view_model/active_record/update_data.rb', line 343

def functional_update_schema
  UpdateData::Schemas::REFERENCED_COLLECTION_UPDATE
end

#parse_contents(values) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/view_model/active_record/update_data.rb', line 359

def parse_contents(values)
  invalid_entries = values.reject { |h| ref_hash?(h) }

  if invalid_entries.present?
    raise ViewModel::DeserializationError::InvalidSyntax.new(
      "Appended/Updated entities must be specified as '#{ViewModel::REFERENCE_ATTRIBUTE}' style hashes." \
      "Invalid entries: #{invalid_entries}",
      blame_reference)
  end

  values.map do |x|
    ref = ViewModel.(x)
    unless valid_reference_keys.include?(ref)
      raise ViewModel::DeserializationError::InvalidSharedReference.new(ref, blame_reference)
    end

    ref
  end
end

#remove_action_schemaObject



351
352
353
# File 'lib/view_model/active_record/update_data.rb', line 351

def remove_action_schema
  UpdateData::Schemas::REFERENCED_REMOVE_ACTION
end

#update_action_schemaObject



355
356
357
# File 'lib/view_model/active_record/update_data.rb', line 355

def update_action_schema
  UpdateData::Schemas::REFERENCED_UPDATE_ACTION
end