mongo 1.10.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +190 -0
- data/README.md +149 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/bin/mongo_console +43 -0
- data/ext/jsasl/target/jsasl.jar +0 -0
- data/lib/mongo.rb +90 -0
- data/lib/mongo/bulk_write_collection_view.rb +380 -0
- data/lib/mongo/collection.rb +1164 -0
- data/lib/mongo/collection_writer.rb +364 -0
- data/lib/mongo/connection.rb +19 -0
- data/lib/mongo/connection/node.rb +239 -0
- data/lib/mongo/connection/pool.rb +347 -0
- data/lib/mongo/connection/pool_manager.rb +325 -0
- data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
- data/lib/mongo/connection/socket.rb +18 -0
- data/lib/mongo/connection/socket/socket_util.rb +37 -0
- data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
- data/lib/mongo/connection/socket/tcp_socket.rb +86 -0
- data/lib/mongo/connection/socket/unix_socket.rb +39 -0
- data/lib/mongo/cursor.rb +719 -0
- data/lib/mongo/db.rb +735 -0
- data/lib/mongo/exception.rb +88 -0
- data/lib/mongo/functional.rb +21 -0
- data/lib/mongo/functional/authentication.rb +318 -0
- data/lib/mongo/functional/logging.rb +85 -0
- data/lib/mongo/functional/read_preference.rb +174 -0
- data/lib/mongo/functional/sasl_java.rb +48 -0
- data/lib/mongo/functional/uri_parser.rb +374 -0
- data/lib/mongo/functional/write_concern.rb +66 -0
- data/lib/mongo/gridfs.rb +18 -0
- data/lib/mongo/gridfs/grid.rb +112 -0
- data/lib/mongo/gridfs/grid_ext.rb +53 -0
- data/lib/mongo/gridfs/grid_file_system.rb +163 -0
- data/lib/mongo/gridfs/grid_io.rb +484 -0
- data/lib/mongo/legacy.rb +140 -0
- data/lib/mongo/mongo_client.rb +702 -0
- data/lib/mongo/mongo_replica_set_client.rb +523 -0
- data/lib/mongo/mongo_sharded_client.rb +159 -0
- data/lib/mongo/networking.rb +370 -0
- data/lib/mongo/utils.rb +19 -0
- data/lib/mongo/utils/conversions.rb +110 -0
- data/lib/mongo/utils/core_ext.rb +70 -0
- data/lib/mongo/utils/server_version.rb +69 -0
- data/lib/mongo/utils/support.rb +80 -0
- data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
- data/mongo.gemspec +36 -0
- data/test/functional/authentication_test.rb +35 -0
- data/test/functional/bulk_api_stress_test.rb +133 -0
- data/test/functional/bulk_write_collection_view_test.rb +1129 -0
- data/test/functional/client_test.rb +565 -0
- data/test/functional/collection_test.rb +2073 -0
- data/test/functional/collection_writer_test.rb +83 -0
- data/test/functional/conversions_test.rb +163 -0
- data/test/functional/cursor_fail_test.rb +63 -0
- data/test/functional/cursor_message_test.rb +57 -0
- data/test/functional/cursor_test.rb +625 -0
- data/test/functional/db_api_test.rb +819 -0
- data/test/functional/db_connection_test.rb +27 -0
- data/test/functional/db_test.rb +344 -0
- data/test/functional/grid_file_system_test.rb +285 -0
- data/test/functional/grid_io_test.rb +252 -0
- data/test/functional/grid_test.rb +273 -0
- data/test/functional/pool_test.rb +62 -0
- data/test/functional/safe_test.rb +98 -0
- data/test/functional/ssl_test.rb +29 -0
- data/test/functional/support_test.rb +62 -0
- data/test/functional/timeout_test.rb +58 -0
- data/test/functional/uri_test.rb +330 -0
- data/test/functional/write_concern_test.rb +118 -0
- data/test/helpers/general.rb +50 -0
- data/test/helpers/test_unit.rb +317 -0
- data/test/replica_set/authentication_test.rb +35 -0
- data/test/replica_set/basic_test.rb +174 -0
- data/test/replica_set/client_test.rb +341 -0
- data/test/replica_set/complex_connect_test.rb +77 -0
- data/test/replica_set/connection_test.rb +138 -0
- data/test/replica_set/count_test.rb +64 -0
- data/test/replica_set/cursor_test.rb +212 -0
- data/test/replica_set/insert_test.rb +140 -0
- data/test/replica_set/max_values_test.rb +145 -0
- data/test/replica_set/pinning_test.rb +55 -0
- data/test/replica_set/query_test.rb +73 -0
- data/test/replica_set/read_preference_test.rb +214 -0
- data/test/replica_set/refresh_test.rb +175 -0
- data/test/replica_set/replication_ack_test.rb +94 -0
- data/test/replica_set/ssl_test.rb +32 -0
- data/test/sharded_cluster/basic_test.rb +197 -0
- data/test/shared/authentication/basic_auth_shared.rb +286 -0
- data/test/shared/authentication/bulk_api_auth_shared.rb +259 -0
- data/test/shared/authentication/gssapi_shared.rb +164 -0
- data/test/shared/authentication/sasl_plain_shared.rb +96 -0
- data/test/shared/ssl_shared.rb +235 -0
- data/test/test_helper.rb +56 -0
- data/test/threading/basic_test.rb +120 -0
- data/test/tools/mongo_config.rb +608 -0
- data/test/tools/mongo_config_test.rb +160 -0
- data/test/unit/client_test.rb +347 -0
- data/test/unit/collection_test.rb +166 -0
- data/test/unit/connection_test.rb +325 -0
- data/test/unit/cursor_test.rb +299 -0
- data/test/unit/db_test.rb +136 -0
- data/test/unit/grid_test.rb +76 -0
- data/test/unit/mongo_sharded_client_test.rb +48 -0
- data/test/unit/node_test.rb +93 -0
- data/test/unit/pool_manager_test.rb +142 -0
- data/test/unit/read_pref_test.rb +115 -0
- data/test/unit/read_test.rb +159 -0
- data/test/unit/safe_test.rb +158 -0
- data/test/unit/sharding_pool_manager_test.rb +84 -0
- data/test/unit/write_concern_test.rb +175 -0
- metadata +260 -0
- metadata.gz.sig +0 -0
data/lib/mongo/utils.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
require 'mongo/utils/conversions'
|
|
16
|
+
require 'mongo/utils/core_ext'
|
|
17
|
+
require 'mongo/utils/server_version'
|
|
18
|
+
require 'mongo/utils/support'
|
|
19
|
+
require 'mongo/utils/thread_local_variable_manager'
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
module Mongo #:nodoc:
|
|
16
|
+
|
|
17
|
+
# Utility module to include when needing to convert certain types of
|
|
18
|
+
# objects to mongo-friendly parameters.
|
|
19
|
+
module Conversions
|
|
20
|
+
|
|
21
|
+
ASCENDING_CONVERSION = ["ascending", "asc", "1"]
|
|
22
|
+
DESCENDING_CONVERSION = ["descending", "desc", "-1"]
|
|
23
|
+
|
|
24
|
+
# Allows sort parameters to be defined as a Hash.
|
|
25
|
+
# Does not allow usage of un-ordered hashes, therefore
|
|
26
|
+
# Ruby 1.8.x users must use BSON::OrderedHash.
|
|
27
|
+
#
|
|
28
|
+
# Example:
|
|
29
|
+
#
|
|
30
|
+
# <tt>hash_as_sort_parameters({:field1 => :asc, "field2" => :desc})</tt> =>
|
|
31
|
+
# <tt>{ "field1" => 1, "field2" => -1}</tt>
|
|
32
|
+
def hash_as_sort_parameters(value)
|
|
33
|
+
if RUBY_VERSION < '1.9' && !value.is_a?(BSON::OrderedHash)
|
|
34
|
+
raise InvalidSortValueError.new(
|
|
35
|
+
"Hashes used to supply sort order must maintain ordering." +
|
|
36
|
+
"Use BSON::OrderedHash."
|
|
37
|
+
)
|
|
38
|
+
else
|
|
39
|
+
order_by = value.inject({}) do |memo, (key, direction)|
|
|
40
|
+
memo[key.to_s] = sort_value(direction)
|
|
41
|
+
memo
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
order_by
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Converts the supplied +Array+ to a +Hash+ to pass to mongo as
|
|
48
|
+
# sorting parameters. The returned +Hash+ will vary depending
|
|
49
|
+
# on whether the passed +Array+ is one or two dimensional.
|
|
50
|
+
#
|
|
51
|
+
# Example:
|
|
52
|
+
#
|
|
53
|
+
# <tt>array_as_sort_parameters([["field1", :asc], ["field2", :desc]])</tt> =>
|
|
54
|
+
# <tt>{ "field1" => 1, "field2" => -1}</tt>
|
|
55
|
+
def array_as_sort_parameters(value)
|
|
56
|
+
order_by = BSON::OrderedHash.new
|
|
57
|
+
if value.first.is_a? Array
|
|
58
|
+
value.each do |param|
|
|
59
|
+
if (param.class.name == "String")
|
|
60
|
+
order_by[param] = 1
|
|
61
|
+
else
|
|
62
|
+
order_by[param[0]] = sort_value(param[1]) unless param[1].nil?
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
elsif !value.empty?
|
|
66
|
+
if order_by.size == 1
|
|
67
|
+
order_by[value.first] = 1
|
|
68
|
+
else
|
|
69
|
+
order_by[value.first] = sort_value(value[1])
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
order_by
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Converts the supplied +String+ or +Symbol+ to a +Hash+ to pass to mongo as
|
|
76
|
+
# a sorting parameter with ascending order. If the +String+
|
|
77
|
+
# is empty then an empty +Hash+ will be returned.
|
|
78
|
+
#
|
|
79
|
+
# Example:
|
|
80
|
+
#
|
|
81
|
+
# *DEPRECATED
|
|
82
|
+
#
|
|
83
|
+
# <tt>string_as_sort_parameters("field")</tt> => <tt>{ "field" => 1 }</tt>
|
|
84
|
+
# <tt>string_as_sort_parameters("")</tt> => <tt>{}</tt>
|
|
85
|
+
def string_as_sort_parameters(value)
|
|
86
|
+
return {} if (str = value.to_s).empty?
|
|
87
|
+
{ str => 1 }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Converts the +String+, +Symbol+, or +Integer+ to the
|
|
91
|
+
# corresponding sort value in MongoDB.
|
|
92
|
+
#
|
|
93
|
+
# Valid conversions (case-insensitive):
|
|
94
|
+
#
|
|
95
|
+
# <tt>ascending, asc, :ascending, :asc, 1</tt> => <tt>1</tt>
|
|
96
|
+
# <tt>descending, desc, :descending, :desc, -1</tt> => <tt>-1</tt>
|
|
97
|
+
#
|
|
98
|
+
# If the value is invalid then an error will be raised.
|
|
99
|
+
def sort_value(value)
|
|
100
|
+
return value if value.is_a?(Hash)
|
|
101
|
+
val = value.to_s.downcase
|
|
102
|
+
return 1 if ASCENDING_CONVERSION.include?(val)
|
|
103
|
+
return -1 if DESCENDING_CONVERSION.include?(val)
|
|
104
|
+
raise InvalidSortValueError.new(
|
|
105
|
+
"#{self} was supplied as a sort direction when acceptable values are: " +
|
|
106
|
+
"Mongo::ASCENDING, 'ascending', 'asc', :ascending, :asc, 1, Mongo::DESCENDING, " +
|
|
107
|
+
"'descending', 'desc', :descending, :desc, -1.")
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
#:nodoc:
|
|
16
|
+
class Object
|
|
17
|
+
|
|
18
|
+
#:nodoc:
|
|
19
|
+
def tap
|
|
20
|
+
yield self
|
|
21
|
+
self
|
|
22
|
+
end unless respond_to? :tap
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#:nodoc:
|
|
27
|
+
class Hash
|
|
28
|
+
|
|
29
|
+
#:nodoc:
|
|
30
|
+
def assert_valid_keys(*valid_keys)
|
|
31
|
+
unknown_keys = keys - [valid_keys].flatten
|
|
32
|
+
raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
#:nodoc:
|
|
38
|
+
class String
|
|
39
|
+
|
|
40
|
+
#:nodoc:
|
|
41
|
+
def to_bson_code
|
|
42
|
+
BSON::Code.new(self)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#:nodoc:
|
|
48
|
+
class Class
|
|
49
|
+
def mongo_thread_local_accessor name, options = {}
|
|
50
|
+
m = Module.new
|
|
51
|
+
m.module_eval do
|
|
52
|
+
class_variable_set :"@@#{name}", Hash.new {|h,k| h[k] = options[:default] }
|
|
53
|
+
end
|
|
54
|
+
m.module_eval %{
|
|
55
|
+
|
|
56
|
+
def #{name}
|
|
57
|
+
@@#{name}[Thread.current.object_id]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def #{name}=(val)
|
|
61
|
+
@@#{name}[Thread.current.object_id] = val
|
|
62
|
+
end
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
class_eval do
|
|
66
|
+
include m
|
|
67
|
+
extend m
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
module Mongo
|
|
16
|
+
|
|
17
|
+
# Simple class for comparing server versions.
|
|
18
|
+
class ServerVersion
|
|
19
|
+
include Comparable
|
|
20
|
+
|
|
21
|
+
def initialize(version)
|
|
22
|
+
@version = version
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Implements comparable.
|
|
26
|
+
def <=>(new)
|
|
27
|
+
local, new = self.to_a, to_array(new)
|
|
28
|
+
for n in 0...local.size do
|
|
29
|
+
break if elements_include_mods?(local[n], new[n])
|
|
30
|
+
if local[n] < new[n].to_i
|
|
31
|
+
result = -1
|
|
32
|
+
break;
|
|
33
|
+
elsif local[n] > new[n].to_i
|
|
34
|
+
result = 1
|
|
35
|
+
break;
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
result || 0
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Return an array representation of this server version.
|
|
42
|
+
def to_a
|
|
43
|
+
to_array(@version)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Return a string representation of this server version.
|
|
47
|
+
def to_s
|
|
48
|
+
@version
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
# Returns true if any elements include mod symbols (-, +)
|
|
54
|
+
def elements_include_mods?(*elements)
|
|
55
|
+
elements.any? { |n| n =~ /[\-\+]/ }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Converts argument to an array of integers,
|
|
59
|
+
# appending any mods as the final element.
|
|
60
|
+
def to_array(version)
|
|
61
|
+
array = version.split(".").map {|n| (n =~ /^\d+$/) ? n.to_i : n }
|
|
62
|
+
if array.last =~ /(\d+)([\-\+])/
|
|
63
|
+
array[array.length-1] = $1.to_i
|
|
64
|
+
array << $2
|
|
65
|
+
end
|
|
66
|
+
array
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
module Mongo
|
|
16
|
+
module Support
|
|
17
|
+
|
|
18
|
+
include Mongo::Conversions
|
|
19
|
+
extend self
|
|
20
|
+
|
|
21
|
+
def validate_db_name(db_name)
|
|
22
|
+
unless [String, Symbol].include?(db_name.class)
|
|
23
|
+
raise TypeError, "db_name must be a string or symbol"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
[" ", ".", "$", "/", "\\"].each do |invalid_char|
|
|
27
|
+
if db_name.include? invalid_char
|
|
28
|
+
raise Mongo::InvalidNSName, "database names cannot contain the character '#{invalid_char}'"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
raise Mongo::InvalidNSName, "database name cannot be the empty string" if db_name.empty?
|
|
32
|
+
db_name
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def format_order_clause(order)
|
|
36
|
+
case order
|
|
37
|
+
when Hash, BSON::OrderedHash then hash_as_sort_parameters(order)
|
|
38
|
+
when String, Symbol then string_as_sort_parameters(order)
|
|
39
|
+
when Array then array_as_sort_parameters(order)
|
|
40
|
+
else
|
|
41
|
+
raise InvalidSortValueError, "Illegal sort clause, '#{order.class.name}'; must be of the form " +
|
|
42
|
+
"[['field1', '(ascending|descending)'], ['field2', '(ascending|descending)']]"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def normalize_seeds(seeds)
|
|
47
|
+
pairs = Array(seeds)
|
|
48
|
+
pairs = [ seeds ] if pairs.last.is_a?(Fixnum)
|
|
49
|
+
pairs = pairs.collect do |hostport|
|
|
50
|
+
if hostport.is_a?(String)
|
|
51
|
+
if hostport[0,1] == '['
|
|
52
|
+
host, port = hostport.split(']:') << MongoClient::DEFAULT_PORT
|
|
53
|
+
host = host.end_with?(']') ? host[1...-1] : host[1..-1]
|
|
54
|
+
else
|
|
55
|
+
host, port = hostport.split(':') << MongoClient::DEFAULT_PORT
|
|
56
|
+
end
|
|
57
|
+
[ host, port.to_i ]
|
|
58
|
+
else
|
|
59
|
+
hostport
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
pairs.length > 1 ? pairs : pairs.first
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def is_i?(value)
|
|
66
|
+
return !!(value =~ /^\d+$/)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Determine if a database command has succeeded by
|
|
70
|
+
# checking the document response.
|
|
71
|
+
#
|
|
72
|
+
# @param [Hash] doc
|
|
73
|
+
#
|
|
74
|
+
# @return [Boolean] true if the 'ok' key is either 1 or *true*.
|
|
75
|
+
def ok?(doc)
|
|
76
|
+
ok = doc['ok']
|
|
77
|
+
ok == 1 || ok == 1.0 || ok == true
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
#:nodoc:
|
|
16
|
+
module Mongo
|
|
17
|
+
module ThreadLocalVariableManager
|
|
18
|
+
def thread_local
|
|
19
|
+
Thread.current[:mongo_thread_locals] ||= Hash.new do |hash, key|
|
|
20
|
+
hash[key] = Hash.new unless hash.key? key
|
|
21
|
+
hash[key]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/mongo.gemspec
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'mongo'
|
|
3
|
+
|
|
4
|
+
s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION'))
|
|
5
|
+
s.platform = Gem::Platform::RUBY
|
|
6
|
+
s.authors = ['Emily Stolfo', 'Durran Jordan', 'Gary Murakami', 'Tyler Brock', 'Brandon Black']
|
|
7
|
+
s.email = 'mongodb-dev@googlegroups.com'
|
|
8
|
+
s.homepage = 'http://www.mongodb.org'
|
|
9
|
+
s.summary = 'Ruby driver for MongoDB'
|
|
10
|
+
s.description = 'A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.'
|
|
11
|
+
s.rubyforge_project = 'mongo'
|
|
12
|
+
s.license = 'Apache License Version 2.0'
|
|
13
|
+
|
|
14
|
+
if File.exists?('gem-private_key.pem')
|
|
15
|
+
s.signing_key = 'gem-private_key.pem'
|
|
16
|
+
s.cert_chain = ['gem-public_cert.pem']
|
|
17
|
+
else
|
|
18
|
+
warn 'Warning: No private key present, creating unsigned gem.'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
s.files = ['mongo.gemspec', 'LICENSE', 'VERSION']
|
|
22
|
+
s.files += ['README.md', 'Rakefile', 'bin/mongo_console']
|
|
23
|
+
s.files += ['lib/mongo.rb'] + Dir['lib/mongo/**/*.rb']
|
|
24
|
+
|
|
25
|
+
if RUBY_PLATFORM =~ /java/
|
|
26
|
+
s.platform = 'java'
|
|
27
|
+
s.files << 'ext/jsasl/target/jsasl.jar'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
s.test_files = Dir['test/**/*.rb'] - Dir['test/bson/*']
|
|
31
|
+
s.executables = ['mongo_console']
|
|
32
|
+
s.require_paths = ['lib']
|
|
33
|
+
s.has_rdoc = 'yard'
|
|
34
|
+
|
|
35
|
+
s.add_dependency('bson', "~> #{s.version}")
|
|
36
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Copyright (C) 2009-2013 MongoDB, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
require 'test_helper'
|
|
16
|
+
require 'shared/authentication/basic_auth_shared'
|
|
17
|
+
require 'shared/authentication/sasl_plain_shared'
|
|
18
|
+
require 'shared/authentication/bulk_api_auth_shared'
|
|
19
|
+
require 'shared/authentication/gssapi_shared'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AuthenticationTest < Test::Unit::TestCase
|
|
23
|
+
include Mongo
|
|
24
|
+
include BasicAuthTests
|
|
25
|
+
include SASLPlainTests
|
|
26
|
+
include BulkAPIAuthTests
|
|
27
|
+
include GSSAPITests
|
|
28
|
+
|
|
29
|
+
def setup
|
|
30
|
+
@client = MongoClient.new(TEST_HOST, TEST_PORT)
|
|
31
|
+
@version = @client.server_version
|
|
32
|
+
@db = @client[TEST_DB]
|
|
33
|
+
@host_info = host_port
|
|
34
|
+
end
|
|
35
|
+
end
|