Module: Eco::API::UseCases::GraphQL::Helpers::Location::Base::TreeTracking
- Includes:
- Base::CaseEnv
- Included in:
- Eco::API::UseCases::GraphQL::Helpers::Location::Base
- Defined in:
- lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb
Constant Summary collapse
- TAGTREE_BACKUP =
'cache/tagtree.json'.freeze
Instance Attribute Summary collapse
-
#current_tree ⇒ Object
Returns the value of attribute current_tree.
-
#previous_tree ⇒ Object
Returns the value of attribute previous_tree.
Attributes included from Lib::ErrorHandling
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#backup_tree(tree = current_tree || live_tree) ⇒ Boolean
Whether or not the backup was created.
-
#track_current_tree(tree) ⇒ Eco::API::Organization::TagTree
At any moment we want to know how the live tree is.
-
#track_current_tree? ⇒ Boolean
Allows to override if the @current_tree should be kept to the latest live version.
Methods included from Language::AuxiliarLogger
Instance Attribute Details
#current_tree ⇒ Object
Returns the value of attribute current_tree.
8 9 10 |
# File 'lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb', line 8 def current_tree @current_tree end |
#previous_tree ⇒ Object
Returns the value of attribute previous_tree.
9 10 11 |
# File 'lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb', line 9 def previous_tree @previous_tree end |
Instance Method Details
#backup_tree(tree = current_tree || live_tree) ⇒ Boolean
Returns whether or not the backup was created.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb', line 65 def backup_tree(tree = current_tree || live_tree) # rubocop:disable Naming/PredicateMethod return false if simulate? case tree when Eco::API::Organization::TagTree tree = tree.source when Hash, Array # that's alright else log(:error) { "Can't back up tagtree. Expecting TagTree, Hash or Array. Given: #{tree.class}" } return false end file = session.file_manager.save_json(tree, self.class::TAGTREE_BACKUP, :timestamp) log(:debug) { "Backed-up tagtree saved locally to #{file}." } true end |
#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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb', line 36 def track_current_tree(tree) return if tree.nil? tree_id = current_tree&.id tree_name = current_tree&.name tree_id = tree.id if tree.respond_to?(:id) tree_name = tree.name if tree.respond_to?(:name) latest_tree = tree if tree.is_a?(Eco::API::Organization::TagTree) if tree.respond_to?(:treeify) latest_tree ||= Eco::API::Organization::TagTree.new( tree.treeify ) end latest_tree.tap do next unless latest_tree.is_a?(Eco::API::Organization::TagTree) next if latest_tree.empty? latest_tree.id = tree_id if latest_tree.id.nil? latest_tree.name = tree_name if latest_tree.name.nil? # a backup happens: self.current_tree = latest_tree end end |
#track_current_tree? ⇒ Boolean
Allows to override if the @current_tree should be kept to the latest live version
13 14 15 |
# File 'lib/eco/api/usecases/graphql/helpers/location/base/tree_tracking.rb', line 13 def track_current_tree? true end |