Sha256: 58bea69c13ae28b6dfc6c7222d37cd44a5f80de5dd1f383ddecedd054ed290bc

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

module ThreeScaleToolbox
  module Commands
    module ServiceCommand
      module CopyCommand
        class CopyMappingRulesTask
          include Task

          def call
            missing_rules.each do |mapping_rule|
              mr_attrs = mapping_rule.attrs.merge('metric_id' => metrics_map.fetch(mapping_rule.metric_id))
              Entities::MappingRule.create(service: target, attrs: mr_attrs)
            end
            logger.info "created #{missing_rules.size} mapping rules"
            report['missing_mapping_rules_created'] = missing_rules.size
          end

          private

          def metrics_map
            @metrics_map ||= source.metrics_mapping(target)
          end

          def missing_rules
            @missing_rules ||= ThreeScaleToolbox::Helper.array_difference(source.mapping_rules, target.mapping_rules) do |source_rule, target_rule|
              source_rule.pattern == target_rule.pattern &&
                source_rule.http_method == target_rule.http_method &&
                source_rule.delta == target_rule.delta &&
                metrics_map.fetch(source_rule.metric_id) == target_rule.metric_id
            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/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/service_command/copy_command/copy_mapping_rules_task.rb