Module: Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff

Includes:
TreeToList
Included in:
Command::DSL
Defined in:
lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb,
lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible.rb,
lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/heading.rb,
lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing.rb,
lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/inputable.rb,
lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/helpers.rb,
lib/eco/api/usecases/graphql/samples/location/service/tree_diff/convertible/parsing/classifications.rb

Overview

Service to spot the differences between an input file and a locations tree. def process compare end

private

def custom_input_csv_transform(csv) csv.add_column('archived') end

def custom_input_row_transform(row) row['archived'] = !as_boolean(row['active']) end end

Examples:

class Custom::UseCase::TagtreeDiff < Eco::API::UseCases::GraphQL::Samples::Location
  name 'tagtree-diff'
  type :other

  require_relative 'cli/10_tagtree_diff_cli'

  include Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeDiff

  IN_FILENAME  = /requested_tree\.csv/.freeze
  IN_FOLDER    = 'sftp'.freeze
  HEADER_MAPS  = {
    'Code'             => 'id',
    'Description'      => 'name',
    'ParentCode'       => 'parent_id',
    'IsActive'         => 'active',
    'LevelDescription' => 'classifications'
  }.freeze
  CLASSIFICATION_MAPS = {
    'Directorate' => 'agency',
    'Subsection'  => 'sub-section',
    'WorkUnit'    => 'work-unit'
  }.freeze

Defined Under Namespace

Modules: Convertible

Constant Summary

Constants included from Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Converter::Discarded

Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Converter::Discarded::DISCARDED_NODES

Constants included from Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Converter::NodeAttrMaps

Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Converter::NodeAttrMaps::NODE_ATTR_MAPS

Constants included from Helpers::Location::Base::TreeTracking

Helpers::Location::Base::TreeTracking::TAGTREE_BACKUP

Constants included from Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Output

Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Output::OUT_FILENAME, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Output::OUT_FOLDER, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Output::OUT_HEADER, Eco::API::UseCases::GraphQL::Samples::Location::Service::TreeToList::Output::OUT_TIME_FORMAT

Instance Attribute Summary

Attributes included from Lib::ErrorHandling

#exception, #exiting

Attributes included from Language::AuxiliarLogger

#logger

Attributes included from Helpers::Location::Base::TreeTracking

#current_tree, #previous_tree

Instance Method Summary collapse

Methods included from Helpers::Location::Base

#live_tree, #session_live_tree, #tagtree_id, #target_structure_id, #target_structure_id_const

Methods included from Language::AuxiliarLogger

#log

Methods included from Helpers::Location::Base::TreeTracking

#backup_tree, #track_current_tree, #track_current_tree?

Instance Method Details

#compareObject



62
63
64
65
66
67
68
# File 'lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb', line 62

def compare
  comparer.tap do |cmp|
    puts comparer.diffs_details if print_diff_details? && cmp.diffs?
    log(:info) { cmp.diffs_summary }
    sleep(5)
  end
end

#comparer(source_1 = live_nodes_list, source_2 = file_nodes_list) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb', line 70

def comparer(
  source_1 = live_nodes_list,
  source_2 = file_nodes_list
)
  @comparer ||= nodes_diff_class.new(
    source_1,
    source_2,
    original_tree: input_tagtree,
    logger:        logger
  ).tap do
    log(:info) {
      "Comparing #{source_1.count} nodes with #{source_2.count} file nodes."
    }
  end
end

#processObject



54
55
56
57
58
59
60
# File 'lib/eco/api/usecases/graphql/samples/location/service/tree_diff.rb', line 54

def process
  with_error_handling do
    next unless compare_live_with_file?

    compare
  end
end