Class: EtnaApp::Magma::Models::CopyTemplate

Inherits:
Etna::Command show all
Includes:
StrongConfirmation, WithEtnaClients, WithLogger
Defined in:
lib/commands.rb

Instance Attribute Summary

Attributes inherited from Etna::Command

#parent

Instance Method Summary collapse

Methods included from StrongConfirmation

#confirm

Methods included from WithLogger

#logger

Methods included from WithEtnaClients

#environment, #exit, exit, #janus_client, #magma_client, #metis_client, #polyphemus_client, #token

Methods inherited from Etna::Command

#completions, #fill_in_missing_params, #find_command, #initialize, parent_scope, #setup

Methods included from Etna::CommandOrExecutor

#command_name, #completions_for, #desc, #flag_argspec, #flag_as_parameter, included, #parse_flags, #program_name, #usage

Constructor Details

This class inherits a constructor from Etna::Command

Instance Method Details

#execute(project_name, target_model: 'project', file: "#{project_name}_models_#{target_model}_tree.csv") ⇒ Object



330
331
332
333
334
335
336
337
338
339
340
# File 'lib/commands.rb', line 330

def execute(project_name, target_model: 'project', file: "#{project_name}_models_#{target_model}_tree.csv")
  unless File.exists?(file)
    puts "File #{file} is being prepared from the #{project_name} project."
    puts "Copying models descending from #{target_model}..."
    prepare_template(file, project_name, target_model)
    puts
    puts "Done!  You can start editing the file #{file} now"
  else
    puts "File #{file} already exists!  Please remove or specify a different file name before running again."
  end
end

#prepare_template(file, project_name, target_model) ⇒ Object



346
347
348
349
350
351
352
353
354
355
# File 'lib/commands.rb', line 346

def prepare_template(file, project_name, target_model)
  tf = Tempfile.new

  begin
    File.open(tf.path, 'wb') { |f| workflow.write_models_template_csv(project_name, target_model, io: f) }
    FileUtils.cp(tf.path, file)
  ensure
    tf.close!
  end
end

#workflowObject



342
343
344
# File 'lib/commands.rb', line 342

def workflow
  @workflow ||= Etna::Clients::Magma::AddProjectModelsWorkflow.new(magma_client: magma_client)
end