Module: Bones::RPC::ReadPreference::Selectable

Included in:
Nearest
Defined in:
lib/bones/rpc/read_preference/selectable.rb

Overview

Provides the shared behaviour for read preferences that can filter by a tag set or add query options.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tagsObject

Since:

  • 2.0.0



14
15
16
# File 'lib/bones/rpc/read_preference/selectable.rb', line 14

def tags
  @tags
end

Instance Method Details

#initialize(tags = nil) ⇒ Object

Instantiate the new taggable read preference.

Examples:

Instantiate the taggable.

Bones::RPC::ReadPreference::Secondary.new({ east_coast: 1 })

Parameters:

  • tags (Array<Hash>) (defaults to: nil)

    The tag sets.

Since:

  • 2.0.0



24
25
26
# File 'lib/bones/rpc/read_preference/selectable.rb', line 24

def initialize(tags = nil)
  @tags = tags
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



38
39
40
41
42
# File 'lib/bones/rpc/read_preference/selectable.rb', line 38

def query_options(options)
  options[:flags] ||= []
  options[:flags] |= [ :slave_ok ]
  options
end