Module: Mongo::Lint Private
- Defined in:
- lib/mongo/lint.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
-
.assert_type(obj, cls) ⇒ Object
private
Raises LintError if
objis not of typecls. - .enabled? ⇒ Boolean private
- .validate_camel_case_read_preference(read_pref) ⇒ Object private
- .validate_camel_case_read_preference_mode(mode) ⇒ Object private
-
.validate_read_concern_option(read_concern) ⇒ Object
private
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).
- .validate_underscore_read_preference(read_pref) ⇒ Object private
- .validate_underscore_read_preference_mode(mode) ⇒ Object private
Class Method Details
.assert_type(obj, cls) ⇒ 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.
Raises LintError if obj is not of type cls.
7 8 9 10 11 12 |
# File 'lib/mongo/lint.rb', line 7 def assert_type(obj, cls) return unless enabled? return if obj.is_a?(cls) raise Error::LintError, "Expected #{obj} to be a #{cls}" end |
.enabled? ⇒ Boolean
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.
94 95 96 |
# File 'lib/mongo/lint.rb', line 94 def enabled? ENV['MONGO_RUBY_DRIVER_LINT'] && %w[1 yes true on].include?(ENV['MONGO_RUBY_DRIVER_LINT'].downcase) end |
.validate_camel_case_read_preference(read_pref) ⇒ 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.
34 35 36 37 38 39 40 |
# File 'lib/mongo/lint.rb', line 34 def validate_camel_case_read_preference(read_pref) return unless enabled? return if read_pref.nil? raise Error::LintError, "Read preference is not a hash: #{read_pref}" unless read_pref.is_a?(Hash) validate_camel_case_read_preference_mode(read_pref[:mode] || read_pref['mode']) end |
.validate_camel_case_read_preference_mode(mode) ⇒ 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.
43 44 45 46 47 48 49 50 |
# File 'lib/mongo/lint.rb', line 43 def validate_camel_case_read_preference_mode(mode) return unless enabled? return unless mode return if %w[primary primaryPreferred secondary secondaryPreferred nearest].include?(mode.to_s) raise Error::LintError, "Invalid read preference mode: #{mode}" end |
.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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/mongo/lint.rb', line 71 def validate_read_concern_option(read_concern) return unless enabled? return if read_concern.nil? raise Error::LintError, "Read concern is not a hash: #{read_concern}" unless read_concern.is_a?(Hash) return if read_concern.empty? keys = read_concern.keys allowed_keys = if read_concern.is_a?(BSON::Document) # Permits indifferent access [ 'level' ] else # Does not permit indifferent access [ :level ] end raise Error::LintError, "Read concern has invalid keys: #{keys.inspect}" if keys != allowed_keys level = read_concern[:level] return if %i[local available majority linearizable snapshot].include?(level) raise Error::LintError, "Read concern level is invalid: value must be a symbol: #{level.inspect}" end |
.validate_underscore_read_preference(read_pref) ⇒ 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.
15 16 17 18 19 20 21 |
# File 'lib/mongo/lint.rb', line 15 def validate_underscore_read_preference(read_pref) return unless enabled? return if read_pref.nil? raise Error::LintError, "Read preference is not a hash: #{read_pref}" unless read_pref.is_a?(Hash) validate_underscore_read_preference_mode(read_pref[:mode] || read_pref['mode']) end |
.validate_underscore_read_preference_mode(mode) ⇒ 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.
24 25 26 27 28 29 30 31 |
# File 'lib/mongo/lint.rb', line 24 def validate_underscore_read_preference_mode(mode) return unless enabled? return unless mode return if %w[primary primary_preferred secondary secondary_preferred nearest].include?(mode.to_s) raise Error::LintError, "Invalid read preference mode: #{mode}" end |