Sha256: c8774ec8a27ffd6446d3e16df806aff28cb3ba83f5202ae48295788c7fd65979

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

module Hako
  module Schedulers
    class EcsDefinitionComparator
      def initialize(expected_container)
        @expected_container = expected_container
      end

      CONTAINER_KEYS = %i[image cpu memory links].freeze
      PORT_MAPPING_KEYS = %i[container_port host_port protocol].freeze
      ENVIRONMENT_KEYS = %i[name value].freeze

      def different?(actual_container)
        unless actual_container
          return true
        end
        if different_members?(@expected_container, actual_container, CONTAINER_KEYS)
          return true
        end
        if @expected_container[:port_mappings].size != actual_container.port_mappings.size
          return true
        end
        @expected_container[:port_mappings].zip(actual_container.port_mappings) do |e, a|
          if different_members?(e, a, PORT_MAPPING_KEYS)
            return true
          end
        end
        if @expected_container[:environment].size != actual_container.environment.size
          return true
        end
        @expected_container[:environment].zip(actual_container.environment) do |e, a|
          if different_members?(e, a, ENVIRONMENT_KEYS)
            return true
          end
        end

        false
      end

      private

      def different_members?(expected, actual, keys)
        keys.each do |key|
          if actual.public_send(key) != expected[key]
            return true
          end
        end
        false
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hako-0.3.0 lib/hako/schedulers/ecs_definition_comparator.rb
hako-0.2.1 lib/hako/schedulers/ecs_definition_comparator.rb
hako-0.2.0 lib/hako/schedulers/ecs_definition_comparator.rb