moped 1.5.3 → 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of moped might be problematic. Click here for more details.

Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -5
  3. data/README.md +1 -1
  4. data/lib/moped.rb +10 -13
  5. data/lib/moped/address.rb +56 -0
  6. data/lib/moped/authenticatable.rb +89 -0
  7. data/lib/moped/cluster.rb +169 -136
  8. data/lib/moped/collection.rb +53 -19
  9. data/lib/moped/connection.rb +69 -10
  10. data/lib/moped/connection/manager.rb +49 -0
  11. data/lib/moped/connection/pool.rb +198 -0
  12. data/lib/moped/connection/queue.rb +93 -0
  13. data/lib/moped/connection/reaper.rb +52 -0
  14. data/lib/moped/connection/socket.rb +4 -0
  15. data/lib/moped/connection/socket/connectable.rb +169 -0
  16. data/lib/moped/connection/socket/ssl.rb +52 -0
  17. data/lib/moped/connection/socket/tcp.rb +25 -0
  18. data/lib/moped/connection/sockets.rb +4 -0
  19. data/lib/moped/cursor.rb +3 -5
  20. data/lib/moped/database.rb +18 -24
  21. data/lib/moped/errors.rb +35 -6
  22. data/lib/moped/executable.rb +96 -0
  23. data/lib/moped/failover.rb +41 -0
  24. data/lib/moped/failover/disconnect.rb +31 -0
  25. data/lib/moped/failover/ignore.rb +29 -0
  26. data/lib/moped/failover/reconfigure.rb +34 -0
  27. data/lib/moped/failover/retry.rb +37 -0
  28. data/lib/moped/indexes.rb +4 -1
  29. data/lib/moped/instrumentable.rb +39 -0
  30. data/lib/moped/instrumentable/log.rb +43 -0
  31. data/lib/moped/instrumentable/noop.rb +31 -0
  32. data/lib/moped/loggable.rb +110 -0
  33. data/lib/moped/node.rb +316 -297
  34. data/lib/moped/operation.rb +3 -0
  35. data/lib/moped/operation/read.rb +62 -0
  36. data/lib/moped/operation/write.rb +57 -0
  37. data/lib/moped/protocol/command.rb +65 -4
  38. data/lib/moped/protocol/commands/authenticate.rb +1 -2
  39. data/lib/moped/protocol/delete.rb +16 -0
  40. data/lib/moped/protocol/get_more.rb +102 -31
  41. data/lib/moped/protocol/insert.rb +17 -0
  42. data/lib/moped/protocol/message.rb +44 -46
  43. data/lib/moped/protocol/query.rb +175 -92
  44. data/lib/moped/protocol/reply.rb +19 -8
  45. data/lib/moped/protocol/update.rb +18 -0
  46. data/lib/moped/query.rb +43 -17
  47. data/lib/moped/read_preference.rb +49 -0
  48. data/lib/moped/read_preference/nearest.rb +55 -0
  49. data/lib/moped/read_preference/primary.rb +60 -0
  50. data/lib/moped/read_preference/primary_preferred.rb +55 -0
  51. data/lib/moped/read_preference/secondary.rb +50 -0
  52. data/lib/moped/read_preference/secondary_preferred.rb +53 -0
  53. data/lib/moped/read_preference/selectable.rb +79 -0
  54. data/lib/moped/readable.rb +55 -0
  55. data/lib/moped/session.rb +122 -70
  56. data/lib/moped/{mongo_uri.rb → uri.rb} +75 -31
  57. data/lib/moped/version.rb +1 -1
  58. data/lib/moped/write_concern.rb +33 -0
  59. data/lib/moped/write_concern/propagate.rb +38 -0
  60. data/lib/moped/write_concern/unverified.rb +28 -0
  61. metadata +79 -44
  62. data/lib/moped/bson.rb +0 -45
  63. data/lib/moped/bson/binary.rb +0 -137
  64. data/lib/moped/bson/code.rb +0 -112
  65. data/lib/moped/bson/document.rb +0 -41
  66. data/lib/moped/bson/extensions.rb +0 -91
  67. data/lib/moped/bson/extensions/array.rb +0 -37
  68. data/lib/moped/bson/extensions/boolean.rb +0 -16
  69. data/lib/moped/bson/extensions/false_class.rb +0 -19
  70. data/lib/moped/bson/extensions/float.rb +0 -22
  71. data/lib/moped/bson/extensions/hash.rb +0 -39
  72. data/lib/moped/bson/extensions/integer.rb +0 -36
  73. data/lib/moped/bson/extensions/nil_class.rb +0 -19
  74. data/lib/moped/bson/extensions/object.rb +0 -11
  75. data/lib/moped/bson/extensions/regexp.rb +0 -38
  76. data/lib/moped/bson/extensions/string.rb +0 -45
  77. data/lib/moped/bson/extensions/symbol.rb +0 -33
  78. data/lib/moped/bson/extensions/time.rb +0 -23
  79. data/lib/moped/bson/extensions/true_class.rb +0 -19
  80. data/lib/moped/bson/max_key.rb +0 -51
  81. data/lib/moped/bson/min_key.rb +0 -51
  82. data/lib/moped/bson/object_id.rb +0 -301
  83. data/lib/moped/bson/timestamp.rb +0 -38
  84. data/lib/moped/bson/types.rb +0 -67
  85. data/lib/moped/logging.rb +0 -58
  86. data/lib/moped/session/context.rb +0 -115
  87. data/lib/moped/sockets/connectable.rb +0 -167
  88. data/lib/moped/sockets/ssl.rb +0 -50
  89. data/lib/moped/sockets/tcp.rb +0 -23
  90. data/lib/moped/threaded.rb +0 -69
@@ -1,137 +0,0 @@
1
- module Moped
2
- module BSON
3
-
4
- # Represents binary data in the BSON specification.
5
- class Binary
6
-
7
- SUBTYPE_MAP = {
8
- generic: 0.chr,
9
- function: 1.chr,
10
- old: 2.chr,
11
- uuid: 3.chr,
12
- md5: 5.chr,
13
- user: 128.chr
14
- }.freeze
15
-
16
- SUBTYPE_TYPES = SUBTYPE_MAP.invert.freeze
17
-
18
- attr_reader :data, :type
19
-
20
- # Dump the binary into it's raw bytes.
21
- #
22
- # @example Dump the binary to raw bytes.
23
- # binary.__bson_dump__(string, "data")
24
- #
25
- # @param [ String ] io The raw bytes to write to.
26
- # @param [ String ] key The field name.
27
- #
28
- # @since 1.0.0
29
- def __bson_dump__(io, key)
30
- io << Types::BINARY
31
- io << key
32
- io << NULL_BYTE
33
-
34
- if type == :old
35
- io << [data.bytesize + 4].pack(INT32_PACK)
36
- io << SUBTYPE_MAP[type]
37
- io << [data.bytesize].pack(INT32_PACK)
38
- io << data
39
- else
40
- io << [data.bytesize].pack(INT32_PACK)
41
- io << SUBTYPE_MAP[type]
42
- io << data
43
- end
44
- end
45
-
46
- # Check equality on the object.
47
- #
48
- # @example Check equality.
49
- # object == other
50
- #
51
- # @param [ Object ] other The object to check against.
52
- #
53
- # @return [ true, false ] If the objects are equal.
54
- #
55
- # @since 1.0.0
56
- def ==(other)
57
- BSON::Binary === other && data == other.data && type == other.type
58
- end
59
- alias :eql? :==
60
-
61
- # Gets the hash code for the object.
62
- #
63
- # @example Get the hash code.
64
- # object.hash
65
- #
66
- # @return [ Fixnum ] The hash code.
67
- #
68
- # @since 1.0.0
69
- def hash
70
- [data, type].hash
71
- end
72
-
73
- # Create the new binary type.
74
- #
75
- # @example Create the new binary.
76
- # Moped::BSON::Binary.new(:md5, data)
77
- #
78
- # @param [ Symbol ] type The type of data. Should be one of :generic,
79
- # :function, :old, :uuid, :md5, :user
80
- # @param [ Object ] data The binary data.
81
- #
82
- # @since 1.0.0
83
- def initialize(type, data)
84
- @type = type
85
- @data = data
86
- end
87
-
88
- # Gets the string inspection for the object.
89
- #
90
- # @example Get the string inspection.
91
- # object.inspect
92
- #
93
- # @return [ String ] The inspection.
94
- #
95
- # @since 1.0.0
96
- def inspect
97
- "#<#{self.class.name} type=#{type.inspect} length=#{data.bytesize}>"
98
- end
99
-
100
- # Get the string representation of the object.
101
- #
102
- # @example Get the string representation.
103
- # object.to_s
104
- #
105
- # @return [ String ] The string representation.
106
- #
107
- # @since 1.0.0
108
- def to_s
109
- data.to_s
110
- end
111
-
112
- class << self
113
-
114
- # Load the BSON from the raw data to a binary.
115
- #
116
- # @example Load the raw data.
117
- # Moped::BSON::Binary.__bson_load__(data)
118
- #
119
- # @param [ String ] io The raw bytes of data.
120
- #
121
- # @return [ Binary ] The binary object.
122
- #
123
- # @since 1.0.0
124
- def __bson_load__(io)
125
- length, = io.read(4).unpack(INT32_PACK)
126
- type = SUBTYPE_TYPES[io.read(1)]
127
- if type == :old
128
- length -= 4
129
- io.read(4)
130
- end
131
- data = io.read(length)
132
- new(type, data)
133
- end
134
- end
135
- end
136
- end
137
- end
@@ -1,112 +0,0 @@
1
- module Moped
2
- module BSON
3
-
4
- # Object representation of a javascript expression.
5
- class Code
6
-
7
- attr_reader :code, :scope
8
-
9
- # Dump the code into it's raw bytes.
10
- #
11
- # @example Dump the code to raw bytes.
12
- # code.__bson_dump__(string, "expression")
13
- #
14
- # @param [ String ] io The raw bytes to write to.
15
- # @param [ String ] key The field name.
16
- #
17
- # @since 1.0.0
18
- def __bson_dump__(io, key)
19
- if scoped?
20
- io << Types::CODE_WITH_SCOPE
21
- io << key.to_bson_cstring
22
- code_start = io.bytesize
23
- io << START_LENGTH
24
- data = code.to_utf8_binary
25
- io << [data.bytesize+1].pack(INT32_PACK)
26
- io << data
27
- io << NULL_BYTE
28
- scope.__bson_dump__(io)
29
- io[code_start, 4] = [io.bytesize - code_start].pack(INT32_PACK)
30
- else
31
- io << Types::CODE
32
- io << key.to_bson_cstring
33
- data = code.to_utf8_binary
34
- io << [data.bytesize+1].pack(INT32_PACK)
35
- io << data
36
- io << NULL_BYTE
37
- end
38
- end
39
-
40
- # Check equality on the object.
41
- #
42
- # @example Check equality.
43
- # object == other
44
- #
45
- # @param [ Object ] other The object to check against.
46
- #
47
- # @return [ true, false ] If the objects are equal.
48
- #
49
- # @since 1.0.0
50
- def ==(other)
51
- BSON::Code === other && code == other.code && scope == other.scope
52
- end
53
- alias :eql? :==
54
-
55
- # Gets the hash code for the object.
56
- #
57
- # @example Get the hash code.
58
- # object.hash
59
- #
60
- # @return [ Fixnum ] The hash code.
61
- #
62
- # @since 1.0.0
63
- def hash
64
- [code, scope].hash
65
- end
66
-
67
- # Create the new code type.
68
- #
69
- # @example Create the new code.
70
- # Moped::BSON::Code.new("this.value = param", param: "test")
71
- #
72
- # @param [ String ] code The javascript code.
73
- # @param [ Object ] scope The scoped variables and values.
74
- #
75
- # @since 1.0.0
76
- def initialize(code, scope = nil)
77
- @code = code
78
- @scope = scope
79
- end
80
-
81
- # Is the code scoped?
82
- #
83
- # @example Is the code scoped?
84
- # code.scoped?
85
- #
86
- # @return [ true, false ] If the code is scoped.
87
- #
88
- # @since 1.0.0
89
- def scoped?
90
- !!scope
91
- end
92
-
93
- class << self
94
-
95
- # Load the BSON from the raw data to a code.
96
- #
97
- # @example Load the raw data.
98
- # Moped::BSON::Code.__bson_load__(data)
99
- #
100
- # @param [ String ] io The raw bytes of data.
101
- #
102
- # @return [ Code ] The code object.
103
- #
104
- # @since 1.0.0
105
- def __bson_load__(io)
106
- code = io.read(*io.read(4).unpack(INT32_PACK)).from_utf8_binary.chop!
107
- new(code)
108
- end
109
- end
110
- end
111
- end
112
- end
@@ -1,41 +0,0 @@
1
- module Moped
2
- module BSON
3
-
4
- # Represents an entire BSON document.
5
- class Document < Hash
6
-
7
- class << self
8
-
9
- # Deserialize the raw bytes into a BSON document object.
10
- #
11
- # @example Deserialize the raw bytes.
12
- # Moped::BSON::Document.deserialize("")
13
- #
14
- # @param [ String ] io The raw bytes.
15
- # @param [ Document ] document The document to load to.
16
- #
17
- # @return [ Document ] The document from the raw bytes.
18
- #
19
- # @since 1.0.0
20
- def deserialize(io, document = new)
21
- __bson_load__(io, document)
22
- end
23
-
24
- # Serialize a document into raw bytes.
25
- #
26
- # @example Serialize the document.
27
- # Moped::BSON::Document.serialize(doc, "")
28
- #
29
- # @param [ Document ] document The document to serialize.
30
- # @param [ String ] io The raw bytes to write to.
31
- #
32
- # @return [ String ] The raw serialized bytes.
33
- #
34
- # @since 1.0.0
35
- def serialize(document, io = "")
36
- document.__bson_dump__(io)
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,91 +0,0 @@
1
- require "moped/bson/extensions/array"
2
- require "moped/bson/extensions/boolean"
3
- require "moped/bson/extensions/false_class"
4
- require "moped/bson/extensions/float"
5
- require "moped/bson/extensions/hash"
6
- require "moped/bson/extensions/integer"
7
- require "moped/bson/extensions/nil_class"
8
- require "moped/bson/extensions/object"
9
- require "moped/bson/extensions/regexp"
10
- require "moped/bson/extensions/string"
11
- require "moped/bson/extensions/symbol"
12
- require "moped/bson/extensions/time"
13
- require "moped/bson/extensions/true_class"
14
-
15
- module Moped
16
- module BSON
17
- module Extensions
18
-
19
- # @private
20
- class ::Array
21
- extend Moped::BSON::Extensions::Array::ClassMethods
22
- include Moped::BSON::Extensions::Array
23
- end
24
-
25
- # @private
26
- class ::FalseClass
27
- extend Moped::BSON::Extensions::Boolean::ClassMethods
28
- include Moped::BSON::Extensions::FalseClass
29
- end
30
-
31
- # @private
32
- class ::Float
33
- extend Moped::BSON::Extensions::Float::ClassMethods
34
- include Moped::BSON::Extensions::Float
35
- end
36
-
37
- # @private
38
- class ::Hash
39
- extend Moped::BSON::Extensions::Hash::ClassMethods
40
- include Moped::BSON::Extensions::Hash
41
- end
42
-
43
- # @private
44
- class ::Integer
45
- extend Moped::BSON::Extensions::Integer::ClassMethods
46
- include Moped::BSON::Extensions::Integer
47
- end
48
-
49
- # @private
50
- class ::NilClass
51
- extend Moped::BSON::Extensions::NilClass::ClassMethods
52
- include Moped::BSON::Extensions::NilClass
53
- end
54
-
55
- # @private
56
- class ::Object
57
- include Moped::BSON::Extensions::Object
58
- end
59
-
60
- # @private
61
- class ::Regexp
62
- extend Moped::BSON::Extensions::Regexp::ClassMethods
63
- include Moped::BSON::Extensions::Regexp
64
- end
65
-
66
- # @private
67
- class ::String
68
- extend Moped::BSON::Extensions::String::ClassMethods
69
- include Moped::BSON::Extensions::String
70
- end
71
-
72
- # @private
73
- class ::Symbol
74
- extend Moped::BSON::Extensions::Symbol::ClassMethods
75
- include Moped::BSON::Extensions::Symbol
76
- end
77
-
78
- # @private
79
- class ::Time
80
- extend Moped::BSON::Extensions::Time::ClassMethods
81
- include Moped::BSON::Extensions::Time
82
- end
83
-
84
- # @private
85
- class ::TrueClass
86
- extend Moped::BSON::Extensions::Boolean::ClassMethods
87
- include Moped::BSON::Extensions::TrueClass
88
- end
89
- end
90
- end
91
- end
@@ -1,37 +0,0 @@
1
- module Moped
2
- module BSON
3
- module Extensions
4
-
5
- module Array
6
-
7
- def __bson_dump__(io, key)
8
- io << Types::ARRAY
9
- io << key.to_bson_cstring
10
- start = io.bytesize
11
- io << START_LENGTH # write dummy length
12
- index, length = 0, self.length
13
- while index < length
14
- slice(index).__bson_dump__(io, index.to_s)
15
- index += 1
16
- end
17
- io << EOD
18
- stop = io.bytesize
19
- io[start, 4] = [stop - start].pack(INT32_PACK)
20
- io
21
- end
22
-
23
- module ClassMethods
24
-
25
- def __bson_load__(io, array = new)
26
- io.read(4) # Swallow the first four (length) bytes
27
- while (buf = io.readbyte) != 0
28
- io.gets(NULL_BYTE)
29
- array << Types::MAP[buf].__bson_load__(io)
30
- end
31
- array
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,16 +0,0 @@
1
- module Moped
2
- module BSON
3
- module Extensions
4
-
5
- module Boolean
6
-
7
- module ClassMethods
8
-
9
- def __bson_load__(io)
10
- io.readbyte == 1
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,19 +0,0 @@
1
- module Moped
2
- module BSON
3
- module Extensions
4
-
5
- module FalseClass
6
-
7
- def __bson_dump__(io, key)
8
- io << Types::BOOLEAN
9
- io << key.to_bson_cstring
10
- io << NULL_BYTE
11
- end
12
-
13
- def __safe_options__
14
- false
15
- end
16
- end
17
- end
18
- end
19
- end