Sha256: 7694004de755dd77c92e8584455e33ce7753ba075ed50cd7c0a1c22d275ce914

Contents?: true

Size: 1.71 KB

Versions: 21

Compression:

Stored size: 1.71 KB

Contents

module Mongo
  module CRUD
    class Requirement
      YAML_KEYS = %w(minServerVersion maxServerVersion topology).freeze

      def initialize(spec)
        @min_server_version = spec['minServerVersion']
        @max_server_version = spec['maxServerVersion']
        @topologies = if topologies = spec['topology']
          topologies.map do |topology|
            {'replicaset' => :replica_set, 'single' => :single, 'sharded' => :sharded}[topology]
          end
        else
          nil
        end
      end

      attr_reader :min_server_version
      attr_reader :max_server_version
      attr_reader :topologies

      def short_min_server_version
        if min_server_version
          min_server_version.split('.')[0..1].join('.')
        else
          nil
        end
      end

      def short_max_server_version
        if max_server_version
          max_server_version.split('.')[0..1].join('.')
        else
          nil
        end
      end

      def satisfied?
        cc = ClusterConfig.instance
        ok = true
        if short_min_server_version
          ok &&= cc.fcv_ish >= short_min_server_version
        end
        if max_server_version
          ok &&= cc.server_version <= max_server_version
        end
        if topologies
          ok &&= topologies.include?(cc.topology)
        end
        ok
      end

      def description
        versions = [min_server_version, max_server_version].compact
        if versions.any?
          versions = versions.join('-')
        else
          versions = nil
        end
        topologies = if self.topologies
          self.topologies.map(&:to_s).join(',')
        else
          nil
        end
        [versions, topologies].compact.join('/')
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
mongo-2.11.6 spec/support/crud/requirement.rb
mongo-2.10.5 spec/support/crud/requirement.rb
mongo-2.11.5 spec/support/crud/requirement.rb
mongo-2.11.4 spec/support/crud/requirement.rb
mongo-2.10.4 spec/support/crud/requirement.rb
mongo-2.11.3 spec/support/crud/requirement.rb
mongo-2.11.2 spec/support/crud/requirement.rb
mongo-2.11.1 spec/support/crud/requirement.rb
mongo-2.10.3 spec/support/crud/requirement.rb
mongo-2.11.0 spec/support/crud/requirement.rb
mongo-2.9.2 spec/support/crud/requirement.rb
mongo-2.10.2 spec/support/crud/requirement.rb
mongo-2.11.0.rc0 spec/support/crud/requirement.rb
mongo-2.10.1 spec/support/crud/requirement.rb
mongo-2.10.0 spec/support/crud/requirement.rb
mongo-2.9.1 spec/support/crud/requirement.rb
mongo-2.10.0.rc0 spec/support/crud/requirement.rb
mongo-2.9.1.rc0 spec/support/crud/requirement.rb
mongo-2.9.0 spec/support/crud/requirement.rb
mongo-2.9.0.rc1 spec/support/crud/requirement.rb