Class: ThreeScaleToolbox::Commands::BackendCommand::CopyCommand::CreateOrUpdateTargetBackendTask
- Inherits:
-
Object
- Object
- ThreeScaleToolbox::Commands::BackendCommand::CopyCommand::CreateOrUpdateTargetBackendTask
show all
- Includes:
- Task
- Defined in:
- lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb
Instance Attribute Summary
Attributes included from Task
#context
Instance Method Summary
collapse
Methods included from Task
#call, #initialize, #logger, #option_target_system_name, #report, #source_backend, #source_backend_ref, #source_remote, #target_backend, #target_backend=, #target_remote
Instance Method Details
#create_attrs ⇒ Object
31
32
33
|
# File 'lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb', line 31
def create_attrs
source_backend.attrs.merge('system_name' => target_backend_ref)
end
|
#run ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb', line 9
def run
backend = Entities::Backend.find(remote: target_remote, ref: target_backend_ref)
if backend.nil?
backend = Entities::Backend.create(remote: target_remote,
attrs: create_attrs)
elsif backend == source_backend
message = 'source and destination backends are the same: ' \
"ID: #{source_backend.id} system_name: #{source_backend.attrs['system_name']}"
warn "\e[1m\e[31mWarning: #{message}\e[0m"
else
backend.update update_attrs
end
self.target_backend = backend
logger.info "source backend ID: #{source_backend.id} system_name: #{source_backend.system_name}"
logger.info "target backend ID: #{target_backend.id} system_name: #{target_backend.system_name}"
report['backend_id'] = target_backend.id
end
|
#target_backend_ref ⇒ Object
39
40
41
|
# File 'lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb', line 39
def target_backend_ref
option_target_system_name || source_backend.attrs.fetch('system_name')
end
|
#update_attrs ⇒ Object
35
36
37
|
# File 'lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb', line 35
def update_attrs
source_backend.attrs.merge('system_name' => target_backend_ref)
end
|