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
@@ -3,18 +3,62 @@ module Moped
3
3
 
4
4
  # Parses MongoDB uri
5
5
  #
6
- # @api public
7
- class MongoUri
6
+ # @since 1.3.0
7
+ class Uri
8
8
 
9
+ # Get the scheme pattern.
10
+ #
11
+ # @since 1.3.0
9
12
  SCHEME = /(mongodb:\/\/)/
13
+
14
+ # The user name pattern.
15
+ #
16
+ # @since 1.3.0
10
17
  USER = /([-.\w:]+)/
18
+
19
+ # The password pattern.
20
+ #
21
+ # @since 1.3.0
11
22
  PASS = /([^@,]+)/
23
+
24
+ # The nodes pattern.
25
+ #
26
+ # @since 1.3.0
12
27
  NODES = /((([-.\w]+)(?::(\w+))?,?)+)/
28
+
29
+ # The database pattern.
30
+ #
31
+ # @since 1.3.0
13
32
  DATABASE = /(?:\/([-\w]+))?/
33
+
34
+ # The options pattern.
35
+ #
36
+ # @since 1.3.0
14
37
  OPTIONS = /(?:\?(.+))/
15
38
 
39
+ # The full URI pattern.
40
+ #
41
+ # @since 1.3.0
16
42
  URI = /#{SCHEME}(#{USER}:#{PASS}@)?#{NODES}#{DATABASE}#{OPTIONS}?/
17
43
 
44
+ # The options that have to do with write concerns.
45
+ #
46
+ # @since 2.0.0
47
+ WRITE_OPTIONS = [ "w", "j", "fsync", "wtimeout" ].freeze
48
+
49
+ # The mappings from read preferences in the URI to Moped's.
50
+ #
51
+ # @since 2.0.0
52
+ READ_MAPPINGS = {
53
+ "nearest" => :nearest,
54
+ "primary" => :primary,
55
+ "primarypreferred" => :primary_preferred,
56
+ "secondary" => :secondary,
57
+ "secondarypreferred" => :secondary_preferred
58
+ }.freeze
59
+
60
+ # @!attribute match
61
+ # @return [ Array ] The uri match.
18
62
  attr_reader :match
19
63
 
20
64
  # Helper to determine if authentication is provided
@@ -75,51 +119,37 @@ module Moped
75
119
  #
76
120
  # @since 1.3.1
77
121
  def invalid_uri!(string)
78
- msg = %{
79
- The given connection string is invalid:
80
- #{string.gsub(/[^:]+@/, '<password>@')}
81
-
82
- MongoDB connection strings must be of the format:
83
- mongodb://host:port/database
84
-
85
- For authentication, include username and password before host:
86
- mongodb://username:password@host:port/database
87
-
88
- For Replica Sets, include multiple host:port entries:
89
- mongodb://host:port,host2:port2/database
90
-
91
- For options, use query string syntax with the option value:
92
- mongodb://host:port/database?safe=true&max_retries=30&timeout=5
93
- }
94
- raise Errors::InvalidMongoURI, msg
122
+ scrubbed = string.gsub(/[^:]+@/, '<password>@')
123
+ raise Errors::InvalidMongoURI, "The provided connection string is not a value URI: #{scrubbed}"
95
124
  end
96
125
 
97
126
  # Get the options provided in the URI.
127
+ #
98
128
  # @example Get the options
99
129
  # uri.options
100
130
  #
131
+ # @note The options provided in the URI string must match the MongoDB
132
+ # specification.
133
+ #
101
134
  # @return [ Hash ] Options hash usable by Moped
102
135
  #
136
+ # @see http://docs.mongodb.org/manual/reference/connection-string/#connections-connection-options
137
+ #
103
138
  # @since 1.3.0
104
139
  def options
105
- options_string, options = @match[10], {database: database}
106
-
140
+ options_string, options = match[10], { database: database }
107
141
  unless options_string.nil?
108
142
  options_string.split(/\&/).each do |option_string|
109
143
  key, value = option_string.split(/=/)
110
-
111
- if value == "true"
112
- options[key.to_sym] = true
113
- elsif value == "false"
114
- options[key.to_sym] = false
115
- elsif value =~ /[\d]/
116
- options[key.to_sym] = value.to_i
144
+ if WRITE_OPTIONS.include?(key)
145
+ options[:write] = { key.to_sym => cast(value) }
146
+ elsif read = READ_MAPPINGS[value.downcase]
147
+ options[:read] = read
117
148
  else
118
- options[key.to_sym] = value.to_sym
149
+ options[key.to_sym] = cast(value)
119
150
  end
120
151
  end
121
152
  end
122
-
123
153
  options
124
154
  end
125
155
 
@@ -160,7 +190,7 @@ For options, use query string syntax with the option value:
160
190
  #
161
191
  # @since 1.3.0
162
192
  def moped_arguments
163
- [hosts, options]
193
+ [ hosts, options ]
164
194
  end
165
195
 
166
196
  # Get the username provided in the URI.
@@ -174,5 +204,19 @@ For options, use query string syntax with the option value:
174
204
  def username
175
205
  @username ||= match[3]
176
206
  end
207
+
208
+ private
209
+
210
+ def cast(value)
211
+ if value == "true"
212
+ true
213
+ elsif value == "false"
214
+ false
215
+ elsif value =~ /[\d]/
216
+ value.to_i
217
+ else
218
+ value.to_sym
219
+ end
220
+ end
177
221
  end
178
222
  end
data/lib/moped/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Moped
3
- VERSION = "1.5.3"
3
+ VERSION = "2.0.0.beta"
4
4
  end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ require "moped/write_concern/propagate"
3
+ require "moped/write_concern/unverified"
4
+
5
+ module Moped
6
+
7
+ # Provides behaviour on getting the correct write concern for an option.
8
+ #
9
+ # @since 2.0.0
10
+ module WriteConcern
11
+ extend self
12
+
13
+ # Get the corresponding write concern for the provided value. If the value
14
+ # is unverified we get that concern, otherwise we get propagate.
15
+ #
16
+ # @example Get the appropriate write concern.
17
+ # Moped::WriteConcern.get(w: 3)
18
+ #
19
+ # @param [ Symbol, String, Hash ] The value to use to get the concern.
20
+ #
21
+ # @return [ Unverified, Propagate ] The appropriate write concern.
22
+ #
23
+ # @since 2.0.0
24
+ def get(value)
25
+ propagate = value[:w] || value["w"]
26
+ if propagate == 0 || propagate == -1
27
+ Unverified.new
28
+ else
29
+ Propagate.new(value)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ module Moped
3
+ module WriteConcern
4
+
5
+ # Propagating write concerns piggyback a getlasterror command to any write
6
+ # operation with the necessary options.
7
+ #
8
+ # @since 2.0.0
9
+ class Propagate
10
+
11
+ # @!attribute operation
12
+ # @return [ Hash ] The gle operation.
13
+ attr_reader :operation
14
+
15
+ # Initialize the propagating write concern.
16
+ #
17
+ # @example Instantiate the write concern.
18
+ # Moped::WriteConcern::Propagate.new(w: 3)
19
+ #
20
+ # @param [ Hash ] operation The operation to execute.
21
+ #
22
+ # @since 2.0.0
23
+ def initialize(options)
24
+ @operation = { getlasterror: 1 }.merge!(normalize(options))
25
+ end
26
+
27
+ private
28
+
29
+ def normalize(options)
30
+ opts = {}
31
+ options.each do |key, value|
32
+ opts[key] = value.is_a?(Symbol) ? value.to_s : value
33
+ end
34
+ opts
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ module Moped
3
+ module WriteConcern
4
+
5
+ # Unverified write concerns are fire and forget.
6
+ #
7
+ # @since 2.0.0
8
+ class Unverified
9
+
10
+ # Constant for a noop getlasterror command.
11
+ #
12
+ # @since 2.0.0
13
+ NOOP = nil
14
+
15
+ # Get the gle command associated with this write concern.
16
+ #
17
+ # @example Get the gle operation.
18
+ # unverified.operation
19
+ #
20
+ # @return [ nil ] nil, since unverified writes perform no gle.
21
+ #
22
+ # @since 2.0.0
23
+ def operation
24
+ NOOP
25
+ end
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,63 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moped
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 2.0.0.beta
5
5
  platform: ruby
6
6
  authors:
7
+ - Durran Jordan
7
8
  - Bernerd Schaefer
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-06-06 00:00:00.000000000 Z
12
- dependencies: []
12
+ date: 2013-09-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bson
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 2.0.0.rc2
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.0.rc2
28
+ - !ruby/object:Gem::Dependency
29
+ name: optionable
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.1.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 0.1.1
13
42
  description: A MongoDB driver for Ruby.
14
43
  email:
15
- - bj.schaefer@gmail.com
44
+ - durran@gmail.com
16
45
  executables: []
17
46
  extensions: []
18
47
  extra_rdoc_files: []
19
48
  files:
20
- - CHANGELOG.md
21
- - LICENSE
22
- - README.md
23
- - lib/moped.rb
24
- - lib/moped/bson.rb
25
- - lib/moped/bson/binary.rb
26
- - lib/moped/bson/code.rb
27
- - lib/moped/bson/document.rb
28
- - lib/moped/bson/extensions.rb
29
- - lib/moped/bson/extensions/array.rb
30
- - lib/moped/bson/extensions/boolean.rb
31
- - lib/moped/bson/extensions/false_class.rb
32
- - lib/moped/bson/extensions/float.rb
33
- - lib/moped/bson/extensions/hash.rb
34
- - lib/moped/bson/extensions/integer.rb
35
- - lib/moped/bson/extensions/nil_class.rb
36
- - lib/moped/bson/extensions/object.rb
37
- - lib/moped/bson/extensions/regexp.rb
38
- - lib/moped/bson/extensions/string.rb
39
- - lib/moped/bson/extensions/symbol.rb
40
- - lib/moped/bson/extensions/time.rb
41
- - lib/moped/bson/extensions/true_class.rb
42
- - lib/moped/bson/max_key.rb
43
- - lib/moped/bson/min_key.rb
44
- - lib/moped/bson/object_id.rb
45
- - lib/moped/bson/timestamp.rb
46
- - lib/moped/bson/types.rb
49
+ - lib/moped/address.rb
50
+ - lib/moped/authenticatable.rb
47
51
  - lib/moped/cluster.rb
48
52
  - lib/moped/collection.rb
53
+ - lib/moped/connection/manager.rb
54
+ - lib/moped/connection/pool.rb
55
+ - lib/moped/connection/queue.rb
56
+ - lib/moped/connection/reaper.rb
57
+ - lib/moped/connection/socket/connectable.rb
58
+ - lib/moped/connection/socket/ssl.rb
59
+ - lib/moped/connection/socket/tcp.rb
60
+ - lib/moped/connection/socket.rb
61
+ - lib/moped/connection/sockets.rb
49
62
  - lib/moped/connection.rb
50
63
  - lib/moped/cursor.rb
51
64
  - lib/moped/database.rb
52
65
  - lib/moped/errors.rb
66
+ - lib/moped/executable.rb
67
+ - lib/moped/failover/disconnect.rb
68
+ - lib/moped/failover/ignore.rb
69
+ - lib/moped/failover/reconfigure.rb
70
+ - lib/moped/failover/retry.rb
71
+ - lib/moped/failover.rb
53
72
  - lib/moped/indexes.rb
54
- - lib/moped/logging.rb
55
- - lib/moped/mongo_uri.rb
73
+ - lib/moped/instrumentable/log.rb
74
+ - lib/moped/instrumentable/noop.rb
75
+ - lib/moped/instrumentable.rb
76
+ - lib/moped/loggable.rb
56
77
  - lib/moped/node.rb
57
- - lib/moped/protocol.rb
78
+ - lib/moped/operation/read.rb
79
+ - lib/moped/operation/write.rb
80
+ - lib/moped/operation.rb
58
81
  - lib/moped/protocol/command.rb
59
- - lib/moped/protocol/commands.rb
60
82
  - lib/moped/protocol/commands/authenticate.rb
83
+ - lib/moped/protocol/commands.rb
61
84
  - lib/moped/protocol/delete.rb
62
85
  - lib/moped/protocol/get_more.rb
63
86
  - lib/moped/protocol/insert.rb
@@ -66,14 +89,26 @@ files:
66
89
  - lib/moped/protocol/query.rb
67
90
  - lib/moped/protocol/reply.rb
68
91
  - lib/moped/protocol/update.rb
92
+ - lib/moped/protocol.rb
69
93
  - lib/moped/query.rb
94
+ - lib/moped/read_preference/nearest.rb
95
+ - lib/moped/read_preference/primary.rb
96
+ - lib/moped/read_preference/primary_preferred.rb
97
+ - lib/moped/read_preference/secondary.rb
98
+ - lib/moped/read_preference/secondary_preferred.rb
99
+ - lib/moped/read_preference/selectable.rb
100
+ - lib/moped/read_preference.rb
101
+ - lib/moped/readable.rb
70
102
  - lib/moped/session.rb
71
- - lib/moped/session/context.rb
72
- - lib/moped/sockets/connectable.rb
73
- - lib/moped/sockets/ssl.rb
74
- - lib/moped/sockets/tcp.rb
75
- - lib/moped/threaded.rb
103
+ - lib/moped/uri.rb
76
104
  - lib/moped/version.rb
105
+ - lib/moped/write_concern/propagate.rb
106
+ - lib/moped/write_concern/unverified.rb
107
+ - lib/moped/write_concern.rb
108
+ - lib/moped.rb
109
+ - CHANGELOG.md
110
+ - LICENSE
111
+ - README.md
77
112
  homepage: http://mongoid.org/en/moped
78
113
  licenses: []
79
114
  metadata: {}
@@ -83,17 +118,17 @@ require_paths:
83
118
  - lib
84
119
  required_ruby_version: !ruby/object:Gem::Requirement
85
120
  requirements:
86
- - - ">="
121
+ - - '>='
87
122
  - !ruby/object:Gem::Version
88
123
  version: '0'
89
124
  required_rubygems_version: !ruby/object:Gem::Requirement
90
125
  requirements:
91
- - - ">="
126
+ - - '>'
92
127
  - !ruby/object:Gem::Version
93
- version: '0'
128
+ version: 1.3.1
94
129
  requirements: []
95
130
  rubyforge_project:
96
- rubygems_version: 2.2.2
131
+ rubygems_version: 2.0.6
97
132
  signing_key:
98
133
  specification_version: 4
99
134
  summary: A MongoDB driver for Ruby.
data/lib/moped/bson.rb DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
- require "moped/bson/extensions"
3
- require "moped/bson/binary"
4
- require "moped/bson/code"
5
- require "moped/bson/object_id"
6
- require "moped/bson/max_key"
7
- require "moped/bson/min_key"
8
- require "moped/bson/timestamp"
9
- require "moped/bson/document"
10
- require "moped/bson/types"
11
-
12
- module Moped
13
-
14
- # The module for Moped's BSON implementation.
15
- module BSON
16
-
17
- EOD = NULL_BYTE = "\u0000".freeze
18
-
19
- INT32_PACK = 'l'.freeze
20
- INT64_PACK = 'q'.freeze
21
- FLOAT_PACK = 'E'.freeze
22
-
23
- START_LENGTH = [0].pack(INT32_PACK).freeze
24
-
25
- BINARY_ENCODING = Encoding.find("binary")
26
- UTF8_ENCODING = Encoding.find("utf-8")
27
-
28
- class << self
29
-
30
- # Create a new object id from the provided string.
31
- #
32
- # @example Create a new object id.
33
- # Moped::BSON::ObjectId("4faf83c7dbf89b7b29000001")
34
- #
35
- # @param [ String ] string The string to use.
36
- #
37
- # @return [ ObjectId ] The object id.
38
- #
39
- # @since 1.0.0
40
- def ObjectId(string)
41
- ObjectId.from_string(string)
42
- end
43
- end
44
- end
45
- end