Sha256: fec3d906def5de9cb599c5adfbf76b112e6698a8aaa30e9584228290f8376c3c

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

module ThreeScaleToolbox
  module Tasks
    class CopyMappingRulesTask
      include CopyTask
      include Helper

      def call
        missing_rules = missing_mapping_rules(source.mapping_rules,
                                              target.mapping_rules, metrics_map)
        missing_rules.each do |mapping_rule|
          mapping_rule.delete('links')
          mapping_rule['metric_id'] = metrics_map.fetch(mapping_rule.delete('metric_id'))
          target.create_mapping_rule mapping_rule
        end
        puts "created #{missing_rules.size} mapping rules"
      end

      private

      def metrics_map
        @metrics_map ||= metrics_mapping(source_metrics_and_methods, target_metrics_and_methods)
      end

      def missing_mapping_rules(source_rules, target_rules, metrics_map)
        ThreeScaleToolbox::Helper.array_difference(source_rules, target_rules) do |source_rule, target_rule|
          ThreeScaleToolbox::Helper.compare_hashes(source_rule, target_rule, %w[pattern http_method delta]) &&
            metrics_map.fetch(source_rule.fetch('metric_id')) == target_rule.fetch('metric_id')
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
3scale_toolbox-0.15.0 lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/tasks/copy_mapping_rules_task.rb