Method: Eco::API::UseCases::GraphQL::Helpers::Location::Base::TreeTracking#track_current_tree

Defined in:
lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb

#track_current_tree(tree) ⇒ Eco::API::Organization::TagTree

Note:

it also does a backup

At any moment we want to know how the live tree is

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb', line 32

def track_current_tree(tree)
  return if simulate?
  return if tree.nil?

  latest_tree = tree if tree.is_a?(Eco::API::Organization::TagTree)
  if tree.respond_to?(:treeify) && track_current_tree?
    latest_tree ||= Eco::API::Organization::TagTree.new(tree.treeify, id: tree.id, name: tree.name)
  end

  latest_tree.tap do
    next unless latest_tree.is_a?(Eco::API::Organization::TagTree)
    next if latest_tree.empty?

    # a backup happens:
    self.current_tree = latest_tree
  end
end