Module: Eco::API::UseCases::GraphQL::Samples::Location::Command::TrackChangedIds
- Includes:
- Helpers::Base::CaseEnv
- Included in:
- DSL
- Defined in:
- lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb
Overview
Logic to: Create tags remap csv table batch design
Constant Summary collapse
- REMAP_LOC_IDS_FOLDER =
'cache'.freeze
- REMAP_LOC_IDS_FILENAME =
'remap_loc_ids.csv'.freeze
Instance Attribute Summary collapse
-
#tags_remap_csv_file ⇒ Object
Returns the value of attribute tags_remap_csv_file.
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#close_handling_tags_remap_csv ⇒ Object
Generates the file.
-
#generate_tags_remap_csv(filename = tags_remap_csv_full_filename) ⇒ Object
Generates the final tags remap file.
- #tags_remap_class ⇒ Object
- #tags_remap_csv_full_filename ⇒ Object
-
#tags_remap_table ⇒ Array<Array>
The maps of tags to be used in batch remap tags.
-
#timestamp_file(filename, enviro_relative: true) ⇒ Object
Makes the file relative to the enviro.
-
#update_tags_remap_table(results, stage, ref_tree = nil) ⇒ Boolean
Based on commands that succeded, and the batch stage, it tracks the tag remaps that should be batches against existing pages.
Methods included from Language::AuxiliarLogger
Instance Attribute Details
#tags_remap_csv_file ⇒ Object
Returns the value of attribute tags_remap_csv_file.
6 7 8 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 6 def @tags_remap_csv_file end |
Instance Method Details
#close_handling_tags_remap_csv ⇒ Object
this method used to only work if we could run cummulative dry-runs to the back-end. However, after RS P3, as mappings are one-to-one (not many-to-many per row), we can just display the mappings in dry-run as well.
Generates the file
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 31 def if .any? puts "REMAP LOC IDs CSV (content):" puts true else log(:info) { "Remap location ids NOT needed :)" } false end end |
#generate_tags_remap_csv(filename = tags_remap_csv_full_filename) ⇒ Object
Generates the final tags remap file
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 72 def (filename = ) return nil if .empty? (filename).tap do |file| CSV.open(file, 'w') do |csv| csv << %w[prev_node_ids new_node_ids] .each do || csv << .to_csv_row end end log(:info) { "Generated file '#{file}'" } end end |
#tags_remap_class ⇒ Object
17 18 19 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 17 def Eco::API::UseCases::GraphQL::Helpers::Location::TagsRemap end |
#tags_remap_csv_full_filename ⇒ Object
11 12 13 14 15 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 11 def folder = self.class::REMAP_LOC_IDS_FOLDER filename = self.class::REMAP_LOC_IDS_FILENAME File.join(folder, filename) end |
#tags_remap_table ⇒ Array<Array>
The maps of tags to be used in batch remap tags
23 24 25 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 23 def @tags_remap_table ||= .new end |
#timestamp_file(filename, enviro_relative: true) ⇒ Object
Makes the file relative to the enviro
86 87 88 89 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 86 def (filename, enviro_relative: true) filename = session.file_manager.dir.file(filename) if enviro_relative Eco::Data::Files.(filename) end |
#update_tags_remap_table(results, stage, ref_tree = nil) ⇒ Boolean
The only update operation that generate tag remaps
is :id
(or :id_name
).
Based on commands that succeded, and the batch stage, it tracks the tag remaps that should be batches against existing pages
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/eco/api/usecases/graphql/samples/location/command/track_changed_ids.rb', line 47 def (results, stage, ref_tree = nil) return false unless %i[id id_name].include?(stage) msg = "Expecting CommandResults object. Given: #{results.class}" raise msg unless results.is_a?(request_results_class) target = simulate?? results.results : results.applied target.each do |result| prev_id, new_id = result.command_input_data.values_at(:nodeId, :newId) next if new_id.nil? # not an id change next if prev_id == new_id << [[prev_id], [new_id]] # next unless ref_tree.is_a?(Eco::API::Organization::TagTree) # next unless ref_tree.tag?(new_id) # msg = "Node '#{prev_id}' was updated to '#{new_id}', " # msg << "but in current structure '#{new_id}' is not present" # log(:warn) { msg } end end |