Class: Etna::Clients::Magma::SimpleFileLinkingWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Magma::SimpleFileLinkingWorkflow
- Defined in:
- lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
Returns the value of attribute attribute_name.
-
#bucket_name ⇒ Object
Returns the value of attribute bucket_name.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#file_collection ⇒ Object
Returns the value of attribute file_collection.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#metis_client ⇒ Object
Returns the value of attribute metis_client.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#regex ⇒ Object
Returns the value of attribute regex.
Instance Method Summary collapse
Instance Attribute Details
#attribute_name ⇒ Object
Returns the value of attribute attribute_name
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def attribute_name @attribute_name end |
#bucket_name ⇒ Object
Returns the value of attribute bucket_name
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def bucket_name @bucket_name end |
#extension ⇒ Object
Returns the value of attribute extension
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def extension @extension end |
#file_collection ⇒ Object
Returns the value of attribute file_collection
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def file_collection @file_collection end |
#folder ⇒ Object
Returns the value of attribute folder
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def folder @folder end |
#metis_client ⇒ Object
Returns the value of attribute metis_client
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def metis_client @metis_client end |
#project_name ⇒ Object
Returns the value of attribute project_name
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def project_name @project_name end |
#regex ⇒ Object
Returns the value of attribute regex
143 144 145 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 143 def regex @regex end |
Instance Method Details
#find_matching_revisions ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 153 def find_matching_revisions {}.tap do |revisions| metis_client.find( Etna::Clients::Metis::FindRequest.new( project_name: project_name, bucket_name: bucket_name, params: [Etna::Clients::Metis::FindParam.new( attribute: 'name', predicate: 'glob', value: "#{folder}/**/*.#{extension}", type: 'file' )] )).files.all.each do |file| puts "Checking #{file.file_path}" match = regex.match(file.file_path) if match match_map = match.names.zip(match.captures).to_h if !match_map.include?('identifier') raise "Regex #{regex.source} does not include a ?<identifier> named matcher, please add one to regulate how identifiers are created." end puts "Found match" revision = { 'path' => "metis://#{project_name}/#{bucket_name}/#{file.file_path}", 'original_filename' => "#{File.basename(file.file_path)}" } if file_collection collection = revisions[match_map['identifier']] ||= [] collection << revision else record = revisions[match_map['identifier']] ||= {} unless record.empty? raise "Multiple files match #{match_map['identifier']}, found #{record['path']} and #{revision['path']}" end record.update(revision) end end end end end |
#write_csv_io(filename: nil, output_io: nil) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/etna/clients/magma/workflows/update_attributes_from_csv_workflow.rb', line 144 def write_csv_io(filename: nil, output_io: nil) exporter = Etna::CsvExporter.new([:identifier, attribute_name.to_sym]) exporter.with_row_writeable(filename: filename, output_io: output_io) do |row_writeable| find_matching_revisions.each do |identifier, value| row_writeable << { identifier: identifier, attribute_name.to_sym => value.to_json } end end end |