Sha256: 64918e41e26484a8872e28f539106c268a2fd3755af2fb1889f945dd278d577a

Contents?: true

Size: 1.34 KB

Versions: 17

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8
require "moped/read_preference/selectable"
require "moped/read_preference/nearest"
require "moped/read_preference/primary"
require "moped/read_preference/primary_preferred"
require "moped/read_preference/secondary"
require "moped/read_preference/secondary_preferred"

module Moped

  # Provides behaviour around getting various read preference implementations.
  #
  # @since 2.0.0
  module ReadPreference
    extend self

    # Hash lookup for the read preference classes based off the symbols
    # provided in configuration.
    #
    # @since 2.0.0
    PREFERENCES = {
      nearest: Nearest,
      primary: Primary,
      primary_preferred: PrimaryPreferred,
      secondary: Secondary,
      secondary_preferred: SecondaryPreferred
    }.freeze

    # Get a read preference for the provided name. Valid names are:
    #   - :nearest
    #   - :primary
    #   - :primary_preferred
    #   - :secondary
    #   - :secondary_preferred
    #
    # @example Get the primary read preference.
    #   Moped::ReadPreference.get(:primary)
    #
    # @param [ Symbol ] name The name of the preference.
    # @param [ Array<Hash> ] tags The tag sets to match the node on.
    #
    # @return [ Object ] The appropriate read preference.
    #
    # @since 2.0.0
    def get(name, tags = nil)
      PREFERENCES.fetch(name.to_sym).new(tags)
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/bundler/gems/moped-cf817ca58a85/lib/moped/read_preference.rb
moped-2.0.7 lib/moped/read_preference.rb
moped-2.0.6 lib/moped/read_preference.rb
moped-2.0.5 lib/moped/read_preference.rb
moped-2.0.4 lib/moped/read_preference.rb
moped-2.0.3 lib/moped/read_preference.rb
moped-2.0.2 lib/moped/read_preference.rb
moped-2.0.1 lib/moped/read_preference.rb
moped-2.0.0 lib/moped/read_preference.rb
moped-2.0.0.rc2 lib/moped/read_preference.rb
moped-2.0.0.rc1 lib/moped/read_preference.rb
moped-2.0.0.beta6 lib/moped/read_preference.rb
moped-2.0.0.beta5 lib/moped/read_preference.rb
moped-2.0.0.beta4 lib/moped/read_preference.rb
moped-2.0.0.beta3 lib/moped/read_preference.rb
moped-2.0.0.beta2 lib/moped/read_preference.rb
moped-2.0.0.beta lib/moped/read_preference.rb