em-synchrony-moped 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -2
- data/em-synchrony-moped.gemspec +5 -4
- data/lib/em-synchrony/moped.rb +24 -1
- metadata +18 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# EM-Synchrony-Moped
|
2
2
|
|
3
|
-
EM-Synchrony-Moped is a [Moped](https://github.com/mongoid/mongoid) driver patch for [EM-Synchrony](http://github.com/igrigorik/em-synchrony). Moped is the MongoDB driver for the [Mongoid](http://github.com/mongoid/mongoid).
|
3
|
+
EM-Synchrony-Moped is a [Moped](https://github.com/mongoid/mongoid) driver patch for [EM-Synchrony](http://github.com/igrigorik/em-synchrony). Moped is the MongoDB driver for the [Mongoid](http://github.com/mongoid/mongoid) ORM.
|
4
4
|
|
5
5
|
* Supports SSL connections
|
6
6
|
|
@@ -11,12 +11,35 @@ In order to use this driver in an EM-Synchrony environment, simply include the d
|
|
11
11
|
```ruby
|
12
12
|
require "em-synchrony/moped"
|
13
13
|
|
14
|
+
EventMachine.synchrony do
|
15
|
+
node = Moped::Node.new("localhost:27017")
|
16
|
+
puts node.primary?
|
17
|
+
EM.stop
|
18
|
+
end
|
19
|
+
|
14
20
|
```
|
15
21
|
|
16
|
-
To use SSL
|
22
|
+
To use SSL, just pass an SSL config section to the options.
|
23
|
+
|
17
24
|
```ruby
|
18
25
|
require "em-synchrony/moped"
|
19
26
|
|
27
|
+
EventMachine.synchrony do
|
28
|
+
options = {
|
29
|
+
:ssl => {
|
30
|
+
:verify_peer => true, # false to skip peer verification
|
31
|
+
:verify_cert => "../path-to/ca_cert.pem", # specify a CA certificate to verify against
|
32
|
+
# or...
|
33
|
+
:cert_store => OpenSSL::X509::Store.new, # to specify a cached cert store.
|
34
|
+
:verify_host => "localhost" # Hostname to verify against, if you wish
|
35
|
+
# to verify the hostname in the certificate.
|
36
|
+
}
|
37
|
+
}
|
38
|
+
node = Moped::Node.new("localhost:27017", options)
|
39
|
+
puts node.primary?
|
40
|
+
EM.stop
|
41
|
+
end
|
42
|
+
|
20
43
|
```
|
21
44
|
|
22
45
|
|
data/em-synchrony-moped.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'em-synchrony-moped'
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Adam Lebsack"]
|
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_runtime_dependency 'eventmachine'
|
22
|
-
s.add_runtime_dependency 'em-synchrony',
|
23
|
-
s.add_runtime_dependency 'moped',
|
22
|
+
s.add_runtime_dependency 'em-synchrony', '~> 1.0'
|
23
|
+
s.add_runtime_dependency 'moped', '~> 1.4.5'
|
24
|
+
s.add_runtime_dependency 'em-resolv-replace', '~> 1.1.3'
|
24
25
|
|
25
|
-
s.add_development_dependency 'rspec',
|
26
|
+
s.add_development_dependency 'rspec', '~> 2.12.0'
|
26
27
|
|
27
28
|
end
|
data/lib/em-synchrony/moped.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require "moped/connection"
|
2
|
+
require "moped/node"
|
3
|
+
require 'em-resolv-replace'
|
2
4
|
|
3
5
|
silence_warnings {
|
4
6
|
|
@@ -9,6 +11,27 @@ silence_warnings {
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
14
|
+
class Node
|
15
|
+
# Override to support non-blocking DNS requests
|
16
|
+
def parse_address
|
17
|
+
host, port = address.split(":")
|
18
|
+
@port = (port || 27017).to_i
|
19
|
+
|
20
|
+
@resolver ||= Resolv.new([Resolv::Hosts.new, Resolv::DNS.new])
|
21
|
+
|
22
|
+
# For now, limit the IPs only to IPv4 hosts. In order to support IPv6,
|
23
|
+
# the node should be able to handle fallback connections.
|
24
|
+
@resolver.getaddresses(host).each do |ip|
|
25
|
+
if ip =~ Resolv::IPv4::Regex
|
26
|
+
@ip_address = ip
|
27
|
+
break
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@resolved_address = "#{@ip_address}:#{@port}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
12
35
|
class Connection
|
13
36
|
def connect
|
14
37
|
@sock = if !!options[:ssl]
|
@@ -89,7 +112,7 @@ silence_warnings {
|
|
89
112
|
end
|
90
113
|
end
|
91
114
|
|
92
|
-
host = @options[:ssl][:verify_host]
|
115
|
+
host = @options[:ssl][:verify_host]
|
93
116
|
if OpenSSL::SSL.verify_certificate_identity(cert, host)
|
94
117
|
@verified = true
|
95
118
|
return true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-synchrony-moped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.4.5
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: em-resolv-replace
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.1.3
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.1.3
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: rspec
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|