moped 2.0.0.beta → 2.0.0.beta2

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13a013a208ac0941e9a6d68d183574f2becafa79
4
- data.tar.gz: 808d31b55227c47ff8d9503918c218d191b6b193
3
+ metadata.gz: d09eab93cd0182d6a05493df401ab183e83e3e2c
4
+ data.tar.gz: ec4275fe3a9c9b7e8e78832f879088f39518895b
5
5
  SHA512:
6
- metadata.gz: 56f954deab2f283830fc371a134d8f1b9055b6d985910886a27ed905a55b58403044f7acd9ea58e363b5dd296858a7dadc152ca8934e048c9fcec7ad60e5d600
7
- data.tar.gz: b568935bcda3e6a73e5601819de389bab69f9e1acba1b40395bd0042b1a062ea86606e787778505fb08a3230855e9cf1b8be57d30925bd6611fe03967a8d1114
6
+ metadata.gz: cdb92718589cc2fd38d8f9297dfc4d898cf9aa3fce14d19bd85b00932e5437909c3ba99f508086b4db963bd11e21d575a0b16e56d818e7c103cc643a110ed591
7
+ data.tar.gz: 7ea98d6a337de3f7b67f48a1ab3a1058b5774d016c5fab87dbd92464d5691f3571db06155c64bec7c73eb6338608f71d06f4b5bf44690ff6f8f3ba3776753c0e
data/CHANGELOG.md CHANGED
@@ -8,6 +8,12 @@
8
8
 
9
9
  ### API Changes (Backwards Incompatible)
10
10
 
11
+ * Query.cursor will return a Enumerable instead of a Enumerator. (Arthur Neves)
12
+
13
+ * Moped's BSON implementation has been removed in favor of the 10gen
14
+ bson gem 2.0 and higher. All `Moped::BSON` references should be changed
15
+ to just `BSON`.
16
+
11
17
  * \#190 Connection retries are now logged. (Jan Paul Posma)
12
18
 
13
19
  * \#133 Moped now supports the new read preferences that the core drivers
@@ -42,6 +48,10 @@
42
48
 
43
49
  The `:safe` option is no longer valid and will be ignored.
44
50
 
51
+ ### Resolved Issues
52
+
53
+ * \#210 Moped no longer attempts to refresh arbiters as they cannot be queried.
54
+
45
55
  ## 1.5.1
46
56
 
47
57
  ### Resolved Issues
data/lib/moped.rb CHANGED
@@ -3,6 +3,7 @@ require "logger"
3
3
  require "stringio"
4
4
  require "monitor"
5
5
  require "timeout"
6
+ require 'resolv'
6
7
  require "bson"
7
8
  require "optionable"
8
9
  require "moped/errors"
data/lib/moped/address.rb CHANGED
@@ -26,10 +26,11 @@ module Moped
26
26
  # @param [ String ] address The host:port pair as a string.
27
27
  #
28
28
  # @since 2.0.0
29
- def initialize(address)
29
+ def initialize(address, timeout)
30
30
  @original = address
31
31
  @host, port = address.split(":")
32
32
  @port = (port || 27017).to_i
33
+ @timeout = timeout
33
34
  end
34
35
 
35
36
  # Resolve the address for the provided node. If the address cannot be
@@ -45,10 +46,18 @@ module Moped
45
46
  # @since 2.0.0
46
47
  def resolve(node)
47
48
  begin
48
- @ip ||= Socket.getaddrinfo(host, nil, Socket::AF_INET, Socket::SOCK_STREAM).first[3]
49
+ Timeout::timeout(@timeout) do
50
+ Resolv.each_address(host) do |ip|
51
+ if ip =~ Resolv::IPv4::Regex
52
+ @ip ||= ip
53
+ break
54
+ end
55
+ end
56
+ raise Resolv::ResolvError unless @ip
57
+ end
49
58
  @resolved ||= "#{ip}:#{port}"
50
- rescue SocketError => e
51
- node.instrument(Node::WARN, prefix: " MOPED:", message: "Could not resolve IP for: #{original}")
59
+ rescue Timeout::Error, Resolv::ResolvError
60
+ Loggable.warn(" MOPED:", "Could not resolve IP for: #{original}", "n/a")
52
61
  node.down! and false
53
62
  end
54
63
  end
data/lib/moped/cluster.rb CHANGED
@@ -302,6 +302,7 @@ module Moped
302
302
  #
303
303
  # @since 2.0.0
304
304
  def refreshable?(node)
305
+ return false if node.arbiter?
305
306
  node.down? ? node.down_at < down_boundary : node.needs_refresh?(refresh_boundary)
306
307
  end
307
308
 
data/lib/moped/cursor.rb CHANGED
@@ -5,6 +5,7 @@ module Moped
5
5
  # @api private
6
6
  class Cursor
7
7
  include Readable
8
+ include Enumerable
8
9
 
9
10
  # @attribute [r] get_more_op The get more message.
10
11
  # @attribute [r] kill_cursor_op The kill cursor message.
@@ -8,12 +8,7 @@ module Moped
8
8
  # The name of the topic of operations for Moped.
9
9
  #
10
10
  # @since 2.0.0
11
- TOPIC = "moped.operations"
12
-
13
- # Topic for warning instrumentation.
14
- #
15
- # @since 2.0.0
16
- WARN = "moped.warn"
11
+ TOPIC = "query.moped"
17
12
 
18
13
  # @!attribute instrumenter
19
14
  # @return [ Object ] The instrumenter
@@ -6,36 +6,30 @@ module Moped
6
6
  # notifications.
7
7
  #
8
8
  # @since 2.0.0
9
- class Log
9
+ module Log
10
+ extend self
10
11
 
11
- class << self
12
-
13
- # Instrument the log payload.
14
- #
15
- # @example Instrument the log payload.
16
- # Log.instrument("moped.ops", {})
17
- #
18
- # @param [ String ] name The name of the logging type.
19
- # @param [ Hash ] payload The log payload.
20
- #
21
- # @return [ Object ] The result of the yield.
22
- #
23
- # @since 2.0.0
24
- def instrument(name, payload = {})
25
- started = Time.new
26
- begin
27
- yield if block_given?
28
- rescue Exception => e
29
- payload[:exception] = [ e.class.name, e.message ]
30
- raise e
31
- ensure
32
- runtime = ("%.4fms" % (1000 * (Time.now.to_f - started.to_f)))
33
- if name == TOPIC
34
- Moped::Loggable.log_operations(payload[:prefix], payload[:ops], runtime)
35
- else
36
- Moped::Loggable.debug(payload[:prefix], payload.reject { |k,v| k == :prefix }, runtime)
37
- end
38
- end
12
+ # Instrument the log payload.
13
+ #
14
+ # @example Instrument the log payload.
15
+ # Log.instrument("moped.ops", {})
16
+ #
17
+ # @param [ String ] name The name of the logging type.
18
+ # @param [ Hash ] payload The log payload.
19
+ #
20
+ # @return [ Object ] The result of the yield.
21
+ #
22
+ # @since 2.0.0
23
+ def instrument(name, payload = {})
24
+ started = Time.new
25
+ begin
26
+ yield if block_given?
27
+ rescue Exception => e
28
+ payload[:exception] = [ e.class.name, e.message ]
29
+ raise e
30
+ ensure
31
+ runtime = ("%.4fms" % (1000 * (Time.now.to_f - started.to_f)))
32
+ Moped::Loggable.log_operations(payload[:prefix], payload[:ops], runtime)
39
33
  end
40
34
  end
41
35
  end
data/lib/moped/node.rb CHANGED
@@ -253,7 +253,6 @@ module Moped
253
253
  #
254
254
  # @since 1.0.0
255
255
  def initialize(address, options = {})
256
- @address = Address.new(address)
257
256
  @options = options
258
257
  @down_at = nil
259
258
  @refreshed_at = nil
@@ -261,6 +260,7 @@ module Moped
261
260
  @primary = nil
262
261
  @secondary = nil
263
262
  @instrumenter = options[:instrumenter] || Instrumentable::Log
263
+ @address = Address.new(address, timeout)
264
264
  @address.resolve(self)
265
265
  end
266
266
 
data/lib/moped/query.rb CHANGED
@@ -13,7 +13,7 @@ module Moped
13
13
  # people.find.skip(2).update(name: "John")
14
14
  # people.find.skip(2).first # => { id: 3, name: "John" }
15
15
  #
16
- # people.find(name: nil).update_all(name: "Unknown")
16
+ # people.find(name: nil).update_all("$set" => { name: "Unknown" })
17
17
  # people.find.one # => { id: 5, name: "Unknown" }
18
18
  # people.find.first # => { id: 5, name: "Unknown" }
19
19
  # people.find.select(name: 0).first # => { id: 5 }
@@ -68,20 +68,18 @@ module Moped
68
68
  # #...
69
69
  # end
70
70
  #
71
- # @return [ Enumerator ] The enumerator.
71
+ # @return [ Enumerable ]
72
72
  #
73
73
  # @since 1.0.0
74
74
  #
75
75
  # @yieldparam [ Hash ] document each matching document
76
- def each
77
- cursor = Cursor.new(session, operation)
78
- enum = cursor.to_enum
79
- enum.each do |document|
80
- yield document
81
- end if block_given?
82
- enum
76
+ def each(*args, &blk)
77
+ cursor.each(*args, &blk)
78
+ end
79
+
80
+ def cursor
81
+ Cursor.new(session, operation)
83
82
  end
84
- alias :cursor :each
85
83
 
86
84
  # Explain the current query.
87
85
  #
@@ -393,7 +391,7 @@ module Moped
393
391
  # Update multiple documents matching the query's selector.
394
392
  #
395
393
  # @example Update multiple documents.
396
- # db[:people].find(name: "John").update_all(name: "Mary")
394
+ # db[:people].find(name: "John").update_all("$set" => { name: "Mary" })
397
395
  #
398
396
  # @param [ Hash ] change The changes to make to the documents
399
397
  #
data/lib/moped/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Moped
3
- VERSION = "2.0.0.beta"
3
+ VERSION = "2.0.0.beta2"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moped
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta
4
+ version: 2.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
12
+ date: 2013-10-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson