Sha256: 51ac06c566c58a0c39a02d024a95a711b306727f26b2a060693c0c08a9a72fb7

Contents?: true

Size: 1.82 KB

Versions: 7

Compression:

Stored size: 1.82 KB

Contents

module ThreeScaleToolbox
  module Commands
    module BackendCommand
      module CopyCommand
        module Task
          attr_reader :context

          def initialize(context)
            @context = context
          end

          def call
            run
          end

          def target_backend=(target)
            context[:target_backend] = target
          end

          def target_backend
            context[:target_backend] ||= raise ThreeScaleToolbox::Error, 'Unexpected error. ' \
              'Target backend should have been created or updated'
          end

          def source_backend
            context[:source_backend] ||= find_source_backend
          end

          def source_remote
            context[:source_remote]
          end

          def target_remote
            context[:target_remote]
          end

          def source_backend_ref
            context[:source_backend_ref] ||= raise ThreeScaleToolbox::Error, 'Unexpected error. ' \
              'source_backend_ref not found'
          end

          def option_target_system_name
            context[:option_target_system_name]
          end

          def logger
            context[:logger] ||= Logger.new($stdout).tap do |logger|
              logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }
            end
          end

          def report
            context[:report] ||= {}
          end

          def delete_mapping_rules
            context.fetch(:delete_mapping_rules, false)
          end

          private

          def find_source_backend
            Entities::Backend.find(remote: source_remote, ref: source_backend_ref).tap do |backend|
              raise ThreeScaleToolbox::Error, "Backend #{source_backend_ref} does not exist" if backend.nil?
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/backend_command/copy_command/task.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/backend_command/copy_command/task.rb