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, #invalidate_target_methods, #invalidate_target_metrics, #option_target_system_name, #source_backend, #source_backend_ref, #source_hits, #source_methods, #source_metrics, #source_remote, #target_backend, #target_backend=, #target_hits, #target_methods, #target_metrics, #target_remote
Instance Method Details
#create_attrs ⇒ Object
30
31
32
|
# File 'lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb', line 30
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
|
# 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
puts "source backend ID: #{source_backend.id} system_name: #{source_backend.attrs['system_name']}"
puts "target backend ID: #{target_backend.id} system_name: #{target_backend.attrs['system_name']}"
end
|
#target_backend_ref ⇒ Object
38
39
40
|
# File 'lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb', line 38
def target_backend_ref
option_target_system_name || source_backend.attrs.fetch('system_name')
end
|
#update_attrs ⇒ Object
34
35
36
|
# File 'lib/3scale_toolbox/commands/backend_command/copy_command/create_or_update_target_backend_task.rb', line 34
def update_attrs
source_backend.attrs.merge('system_name' => target_backend_ref)
end
|