Class: Moped::ReadPreference::Primary

Inherits:
Object
  • Object
show all
Includes:
Selectable
Defined in:
lib/moped/read_preference/primary.rb

Overview

Encapsulates behaviour around a primary read preference.

Since:

  • 2.0.0

Instance Attribute Summary

Attributes included from Selectable

#tags

Instance Method Summary collapse

Methods included from Selectable

#initialize

Instance Method Details

#nameSymbol

Get the name for the read preference on the server side.

Examples:

Get the name of the read preference.

primary.name

Returns:

  • (Symbol)

    :primary.

Since:

  • 2.0.0



19
20
21
# File 'lib/moped/read_preference/primary.rb', line 19

def name
  :primary
end

#query_options(options) ⇒ Hash

Get the provided options as query options for this read preference.

Examples:

Get the query options.

preference.query_options({})

Parameters:

  • options (Hash)

    The existing options for the query.

Returns:

  • (Hash)

    The options plus additional query options.

Since:

  • 2.0.0



33
34
35
# File 'lib/moped/read_preference/primary.rb', line 33

def query_options(options)
  options
end

#with_node(cluster, &block) ⇒ Object

Select a primary node from the cluster. If no primary node is available then an exception will be raised.

Examples:

Select a primary node from the cluster.

preference.with_node(cluster) do |node|
  node.command(ismaster: 1)
end

Parameters:

  • cluster (Cluster)

    The cluster of nodes to select from.

  • block (Proc)

    The block to execute on the node.

Returns:

  • (Object)

    The result of the block.

Raises:

Since:

  • 2.0.0



53
54
55
56
57
# File 'lib/moped/read_preference/primary.rb', line 53

def with_node(cluster, &block)
  with_retry(cluster) do
    cluster.with_primary(&block)
  end
end