class ViewModel::Migrator

def migrate_tree!(node, references:)

def migrate_tree!(node, references:)
  case node
  when Hash
    if (type = node[ViewModel::TYPE_ATTRIBUTE])
      version = node[ViewModel::VERSION_ATTRIBUTE]
      # We allow subtrees to be excluded from migration. This is used
      # internally to permit stub references that are not a full
      # serialization of the referenced type: see ViewModel::Cache.
      return if node[EXCLUDE_FROM_MIGRATION]
      if migrate_viewmodel!(type, version, node, references)
        node[ViewModel::MIGRATED_ATTRIBUTE] = true
      end
    end
    node.each_value do |child|
      migrate_tree!(child, references: references)
    end
  when Array
    node.each { |child| migrate_tree!(child, references: references) }
  end
end