Module: Eco::API::UseCases::GraphQL::Helpers::Location::Base

Includes:
Base, ClassificationsParser, TreeTracking
Included in:
Command, Samples::Location::DSL
Defined in:
lib/eco/api/usecases/graphql/helpers/location/base.rb,
lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb,
lib/eco/api/usecases/graphql/helpers/location/base/classifications_parser.rb

Defined Under Namespace

Modules: ClassificationsParser, TreeTracking

Constant Summary

Constants included from TreeTracking

TreeTracking::TAGTREE_BACKUP

Instance Attribute Summary

Attributes included from Base::ErrorHandling

#exception, #exiting

Attributes included from Language::AuxiliarLogger

#logger

Attributes included from TreeTracking

#current_tree, #previous_tree

Instance Method Summary collapse

Methods included from Language::AuxiliarLogger

#log

Methods included from TreeTracking

#backup_tree, #track_current_tree, #track_current_tree?

Instance Method Details

#live_treeObject

Note:

that target_structure_id can retrive the live tree (when id is not defined) By checking if the current_tree changed after calling target_structure_id we prevent unnecessary requests.

Retrieves the live tree only if current_tree hasn't been just retrieved.



32
33
34
35
36
37
38
39
# File 'lib/eco/api/usecases/graphql/helpers/location/base.rb', line 32

def live_tree
  tree_init = current_tree
  target_id = target_structure_id
  return current_tree if current_tree != tree_init

  # a backup happens:
  self.current_tree = session_live_tree(id: target_id)
end

#session_live_tree(id: nil) ⇒ Object

Note:

ensures archived nodes are retrieved.

Unique access point to retrieve the live tree



43
44
45
# File 'lib/eco/api/usecases/graphql/helpers/location/base.rb', line 43

def session_live_tree(id: nil)
  session.live_tree(id: id, include_archived: true)
end

#tagtree_idObject



47
48
49
50
51
# File 'lib/eco/api/usecases/graphql/helpers/location/base.rb', line 47

def tagtree_id
  %i[target_structure_id tagtree_id structure_id].map do |key|
    options.dig(:source, key)
  end.compact.first
end

#target_structure_idObject

Note:

it is basic that the id is correctly identified.

Scopes the target structure id.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/eco/api/usecases/graphql/helpers/location/base.rb', line 11

def target_structure_id
  @target_structure_id ||= tagtree_id
  @target_structure_id ||= target_structure_id_const
  @target_structure_id ||= current_tree.id if current_tree.respond_to?(:id)
  return @target_structure_id if @target_structure_id

  msg  = "Const TARGET_STRUCTURE_ID has not been defined, "
  msg << "nor options(:source, :structure_id). "
  msg << "Infering active locations structure."
  log(:warn) { msg }

  # a backup happens:
  return nil unless (self.current_tree = session_live_tree)

  @target_structure_id = current_tree.id
end

#target_structure_id_constObject



53
54
55
56
# File 'lib/eco/api/usecases/graphql/helpers/location/base.rb', line 53

def target_structure_id_const
  return nil unless self.class.const_defined?(:TARGET_STRUCTURE_ID)
  self.class.const_get(:TARGET_STRUCTURE_ID)
end