Sha256: 6b465de5ee08e56834691f2479824aaffce71e6902fd8c8b13f7a38b6c40c67b

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

module ThreeScaleToolbox
  module Commands
    module BackendCommand
      module CopyCommand
        class CopyMethodsTask
          include Task

          # entrypoint
          def run
            missing_methods.each(&method(:create_method))
            logger.info "created #{missing_methods.size} missing methods"
            report['missing_methods_created'] = missing_methods.size
          end

          private

          def create_method(method)
            Entities::BackendMethod.create(backend: target_backend, attrs:  method.attrs)
          rescue ThreeScaleToolbox::ThreeScaleApiError => e
            raise e unless ThreeScaleToolbox::Helper.system_name_already_taken_error?(e.apierrors)

            warn "[WARN] backend method #{method.system_name} not created. " \
              'Backend metric with the same system_name exists.'
          end

          def missing_methods
            @missing_methods ||= ThreeScaleToolbox::Helper.array_difference(source_backend.methods, target_backend.methods) do |source, target|
              source.system_name == target.system_name
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/backend_command/copy_command/copy_methods_task.rb