Method: Mongo::Protocol::Msg#initialize
- Defined in:
- lib/mongo/protocol/msg.rb
#initialize(flags, options, main_document, *sequences) ⇒ Msg
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.
Creates a new OP_MSG protocol message
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mongo/protocol/msg.rb', line 66 def initialize(flags, , main_document, *sequences) if flags flags.each do |flag| unless KNOWN_FLAGS.key?(flag) raise ArgumentError, "Unknown flag: #{flag.inspect}" end end end @flags = flags || [] @options = unless main_document.is_a?(Hash) raise ArgumentError, "Main document must be a Hash, given: #{main_document.class}" end @main_document = main_document sequences.each_with_index do |section, index| unless section.is_a?(Section1) raise ArgumentError, "All sequences must be Section1 instances, got: #{section} at index #{index}" end end @sequences = sequences @sections = [ {type: 0, payload: @main_document} ] + @sequences.map do |section| {type: 1, payload: { identifier: section.identifier, sequence: section.documents.map do |doc| CachingHash.new(doc) end, }} end @request_id = nil super end |