class Para::Cloneable::IncludeTreeBuilder

This object acts as a service to compile a nested cloneable options hash to be provided to the ‘deep_clone` method from the `deep_cloneable` gem. It iterates over every reflections that must be included for a given model when it’s cloned, and creates a nested hash of :include and :except directives based on the tree that is created by nested ‘acts_as_cloneable` calls on the different models of the application

Example :

Given the following model structure :

  class Article < ApplicationRecord
    acts_as_cloneable :category, :comments, except: [:publication_date]

    belongs_to :category
    has_many :comments
  end

  class Category < ApplicationRecord
    acts_as_cloneable :category, except: [:articles_count]

    has_many :articles
  end

  class Comment < ApplicationRecord
    acts_as_cloneable :author

    belongs_to :article
    belongs_to :author
  end

  class Author < ApplicationRecord
    acts_as_cloneable except: [:email]

    has_many :articles
  end

The behavior would be :

  Para::Cloneable::IncludeTreeBuilder.new(article).build
  # => {
         include: [:category, { comments: :author }],
         except: [:publication_date, {
           category: [:articles_count],
           comments: { author: [:email] }
         }]
       }