Method: Mongo::Lint.validate_read_concern_option
- Defined in:
- lib/mongo/lint.rb
.validate_read_concern_option(read_concern) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates the provided hash as a read concern object, per the read/write concern specification (github.com/mongodb/specifications/blob/master/source/read-write-concern/read-write-concern.md#read-concern).
This method also accepts nil as input for convenience.
The read concern document as sent to the server may include additional fields, for example afterClusterTime. These fields are generated internally by the driver and cannot be specified by the user (and would potentially lead to incorrect behavior if they were specified by the user), hence this method prohibits them.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mongo/lint.rb', line 76 def validate_read_concern_option(read_concern) return unless enabled? return if read_concern.nil? unless read_concern.is_a?(Hash) raise Error::LintError, "Read concern is not a hash: #{read_concern}" end return if read_concern.empty? keys = read_concern.keys if read_concern.is_a?(BSON::Document) # Permits indifferent access allowed_keys = ['level'] else # Does not permit indifferent access allowed_keys = [:level] end if keys != allowed_keys raise Error::LintError, "Read concern has invalid keys: #{keys.inspect}" end level = read_concern[:level] return if [:local, :available, :majority, :linearizable, :snapshot].include?(level) raise Error::LintError, "Read concern level is invalid: value must be a symbol: #{level.inspect}" end |