Class: EtnaApp::Magma::Models::CopyTemplate
- Inherits:
-
Etna::Command
- Object
- Etna::Command
- EtnaApp::Magma::Models::CopyTemplate
- Includes:
- StrongConfirmation, WithEtnaClients, WithLogger
- Defined in:
- lib/commands.rb
Instance Attribute Summary
Attributes inherited from Etna::Command
Instance Method Summary collapse
- #execute(project_name, target_model: 'project', file: "#{project_name}_models_#{target_model}_tree.csv") ⇒ Object
- #prepare_template(file, project_name, target_model) ⇒ Object
- #workflow ⇒ Object
Methods included from StrongConfirmation
Methods included from WithLogger
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
329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/commands.rb', line 329 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
345 346 347 348 349 350 351 352 353 354 |
# File 'lib/commands.rb', line 345 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 |
#workflow ⇒ Object
341 342 343 |
# File 'lib/commands.rb', line 341 def workflow @workflow ||= Etna::Clients::Magma::AddProjectModelsWorkflow.new(magma_client: magma_client) end |