bson 4.3.0-java → 4.4.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +16 -9
  5. data/lib/bson-ruby.jar +0 -0
  6. data/lib/bson.rb +1 -1
  7. data/lib/bson/active_support.rb +17 -0
  8. data/lib/bson/array.rb +1 -1
  9. data/lib/bson/binary.rb +1 -1
  10. data/lib/bson/boolean.rb +1 -1
  11. data/lib/bson/code.rb +1 -1
  12. data/lib/bson/code_with_scope.rb +1 -1
  13. data/lib/bson/config.rb +1 -1
  14. data/lib/bson/date.rb +1 -1
  15. data/lib/bson/date_time.rb +1 -1
  16. data/lib/bson/decimal128.rb +1 -1
  17. data/lib/bson/decimal128/builder.rb +1 -1
  18. data/lib/bson/document.rb +42 -4
  19. data/lib/bson/environment.rb +1 -1
  20. data/lib/bson/false_class.rb +1 -1
  21. data/lib/bson/float.rb +1 -1
  22. data/lib/bson/hash.rb +1 -1
  23. data/lib/bson/int32.rb +17 -4
  24. data/lib/bson/int64.rb +17 -4
  25. data/lib/bson/integer.rb +2 -2
  26. data/lib/bson/json.rb +1 -1
  27. data/lib/bson/max_key.rb +1 -1
  28. data/lib/bson/min_key.rb +1 -1
  29. data/lib/bson/nil_class.rb +1 -1
  30. data/lib/bson/object.rb +1 -1
  31. data/lib/bson/object_id.rb +1 -1
  32. data/lib/bson/open_struct.rb +1 -1
  33. data/lib/bson/regexp.rb +1 -1
  34. data/lib/bson/registry.rb +1 -1
  35. data/lib/bson/specialized.rb +1 -1
  36. data/lib/bson/string.rb +1 -1
  37. data/lib/bson/symbol.rb +6 -3
  38. data/lib/bson/time.rb +1 -1
  39. data/lib/bson/time_with_zone.rb +54 -0
  40. data/lib/bson/timestamp.rb +1 -1
  41. data/lib/bson/true_class.rb +1 -1
  42. data/lib/bson/undefined.rb +1 -1
  43. data/lib/bson/version.rb +2 -2
  44. data/spec/bson/array_spec.rb +1 -1
  45. data/spec/bson/binary_spec.rb +1 -1
  46. data/spec/bson/boolean_spec.rb +1 -1
  47. data/spec/bson/byte_buffer_spec.rb +40 -0
  48. data/spec/bson/code_spec.rb +1 -1
  49. data/spec/bson/code_with_scope_spec.rb +1 -1
  50. data/spec/bson/date_spec.rb +1 -1
  51. data/spec/bson/date_time_spec.rb +1 -1
  52. data/spec/bson/decimal128_spec.rb +1 -1
  53. data/spec/bson/document_spec.rb +60 -1
  54. data/spec/bson/false_class_spec.rb +1 -1
  55. data/spec/bson/float_spec.rb +1 -1
  56. data/spec/bson/hash_spec.rb +1 -1
  57. data/spec/bson/int32_spec.rb +139 -3
  58. data/spec/bson/int64_spec.rb +139 -3
  59. data/spec/bson/integer_spec.rb +3 -3
  60. data/spec/bson/json_spec.rb +1 -1
  61. data/spec/bson/max_key_spec.rb +1 -1
  62. data/spec/bson/min_key_spec.rb +1 -1
  63. data/spec/bson/nil_class_spec.rb +1 -1
  64. data/spec/bson/object_id_spec.rb +1 -1
  65. data/spec/bson/object_spec.rb +1 -1
  66. data/spec/bson/open_struct_spec.rb +1 -1
  67. data/spec/bson/regexp_spec.rb +1 -1
  68. data/spec/bson/registry_spec.rb +1 -1
  69. data/spec/bson/string_spec.rb +1 -1
  70. data/spec/bson/symbol_spec.rb +3 -3
  71. data/spec/bson/time_spec.rb +1 -1
  72. data/spec/bson/time_with_zone_spec.rb +68 -0
  73. data/spec/bson/timestamp_spec.rb +1 -1
  74. data/spec/bson/true_class_spec.rb +1 -1
  75. data/spec/bson/undefined_spec.rb +1 -1
  76. data/spec/bson_spec.rb +1 -1
  77. data/spec/spec_helper.rb +15 -1
  78. data/spec/support/shared_examples.rb +1 -1
  79. data/spec/support/spec_config.rb +9 -0
  80. metadata +69 -64
  81. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e4db29f7f4d8980b8014e4682d1d5e983049ed64
4
- data.tar.gz: ff3704ebf4dcf34ff0d1f1f28593d4246bc13711
2
+ SHA256:
3
+ metadata.gz: 9f504ac52d583814f30388165b6e3a07a2c59aa748b4fb39567c9561467156b4
4
+ data.tar.gz: 0137c6f9f6673bd48e74c49ced4f270bdea4a6c4e71a3152f910fb24a22bdab1
5
5
  SHA512:
6
- metadata.gz: a12b26ecfaa22dc2d7bd753e15b3fc6e795743ba6dbff8e8f8771dcf47d5f5d7172c2a08e802ec390fd670bd85a0c450b8713bfc74a2322eac88d7413189d1c3
7
- data.tar.gz: 6cd5df5fdab491856c246a3c4d7bb69739361c82c3485b783bb33184bb224f561ba9d5f5ec01bf895db51b31c26d425c5d51606a9b9907e67a6f6f2015e41341
6
+ metadata.gz: 016111afc57e5358c29ea29689305753f9a42055d72fc1de9903c5cd8ac41c17f132500503a6bedd70f6335a96a5bc32e9b97562214977ec353b9dca48ab8b8b
7
+ data.tar.gz: 899e76cd3c91479cc5c9af5a3eb258a1b6f61e4441dd61bec93a5d3174ecc738436dd3b2caab166466b101346e3f1399746a81a40385e60c66c20c891bdaedf9
Binary file
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -20,6 +20,7 @@ $LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
20
20
  require "rake"
21
21
  require "rake/extensiontask"
22
22
  require "rspec/core/rake_task"
23
+ require 'fileutils'
23
24
 
24
25
  def jruby?
25
26
  defined?(JRUBY_VERSION)
@@ -62,15 +63,9 @@ else
62
63
  end
63
64
 
64
65
  task :clean_all => :clean do
65
- begin
66
- Dir.chdir(Pathname(__FILE__).dirname + "lib") do
67
- `rm bson_native.#{extension}`
68
- `rm bson_native.o`
69
- `rm bson-ruby.jar`
70
- end
71
- rescue Exception => e
72
- puts e.message
73
- end
66
+ FileUtils.rm_f(File.join(File.dirname(__FILE__), 'lib', "bson_native.#{extension}"))
67
+ FileUtils.rm_f(File.join(File.dirname(__FILE__), 'lib', "bson_native.o"))
68
+ FileUtils.rm_f(File.join(File.dirname(__FILE__), 'lib', "bson-ruby.jar"))
74
69
  end
75
70
 
76
71
  task :spec => :compile do
@@ -126,3 +121,15 @@ namespace :benchmark do
126
121
  end
127
122
 
128
123
  task :default => [ :clean_all, :spec ]
124
+
125
+ desc "Generate all documentation"
126
+ task :docs => 'docs:yard'
127
+
128
+ namespace :docs do
129
+ desc "Generate yard documention"
130
+ task :yard do
131
+ out = File.join('yard-docs', BSON::VERSION)
132
+ FileUtils.rm_rf(out)
133
+ system "yardoc -o #{out} --title bson-#{BSON::VERSION}"
134
+ end
135
+ end
Binary file
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -0,0 +1,17 @@
1
+ # Copyright (C) 2018-2019 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 this file if using BSON with ActiveSupport.
16
+
17
+ require "bson/time_with_zone"
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2016 MongoDB Inc.
1
+ # Copyright (C) 2016-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2016 MongoDB Inc.
1
+ # Copyright (C) 2016-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2016 MongoDB Inc.
1
+ # Copyright (C) 2016-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -35,8 +35,25 @@ module BSON
35
35
  class Document < ::Hash
36
36
 
37
37
  # Get a value from the document for the provided key. Can use string or
38
- # symbol access, but the fastest will be to always provide a key that is of
39
- # the same type as the stored keys.
38
+ # symbol access, with string access being the faster of the two.
39
+ #
40
+ # @example Get an element for the key.
41
+ # document.fetch("field")
42
+ #
43
+ # @example Get an element for the key by symbol.
44
+ # document.fetch(:field)
45
+ #
46
+ # @param [ String, Symbol ] key The key to look up.
47
+ #
48
+ # @return [ Object ] The found value. Raises KeyError if none found.
49
+ #
50
+ # @since 4.4.0
51
+ def fetch(key)
52
+ super(convert_key(key))
53
+ end
54
+
55
+ # Get a value from the document for the provided key. Can use string or
56
+ # symbol access, with string access being the faster of the two.
40
57
  #
41
58
  # @example Get an element for the key.
42
59
  # document["field"]
@@ -44,7 +61,7 @@ module BSON
44
61
  # @example Get an element for the key by symbol.
45
62
  # document[:field]
46
63
  #
47
- # @param [ String, Symbol ] key The key to lookup.
64
+ # @param [ String, Symbol ] key The key to look up.
48
65
  #
49
66
  # @return [ Object ] The found value, or nil if none found.
50
67
  #
@@ -192,6 +209,27 @@ module BSON
192
209
  end
193
210
  end
194
211
 
212
+ if instance_methods.include?(:slice)
213
+ # Slices a document to include only the given keys.
214
+ # Will normalize symbol keys into strings.
215
+ # (this method is backported from ActiveSupport::Hash)
216
+ #
217
+ # @example Get a document/hash with only the `name` and `age` fields present
218
+ # document # => { _id: <ObjectId>, :name => 'John', :age => 30, :location => 'Earth' }
219
+ # document.slice(:name, 'age') # => { name: 'John', age: 30 }
220
+ # document.slice('name') # => { name: 'John' }
221
+ # document.slice(:foo) # => nil
222
+ #
223
+ # @param [ Array<String, Symbol> ] *keys Keys, that will be kept in the resulting document
224
+ #
225
+ # @return [ BSON::Document ] The document with only the selected keys
226
+ #
227
+ # @since 4.3.1
228
+ def slice(*keys)
229
+ super(*keys.map{|key| convert_key(key)})
230
+ end
231
+ end
232
+
195
233
  private
196
234
 
197
235
  def convert_key(key)
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,8 +14,7 @@
14
14
 
15
15
  module BSON
16
16
 
17
- # Represents a $maxKey type, which compares less than any other value in the
18
- # specification.
17
+ # Represents int32 type.
19
18
  #
20
19
  # @see http://bsonspec.org/#/specification
21
20
  #
@@ -87,9 +86,23 @@ module BSON
87
86
  #
88
87
  # @since 4.2.0
89
88
  def to_bson_key(validating_keys = Config.validating_keys?)
90
- @integer.to_bson_key(validating_keys)
89
+ @integer
91
90
  end
92
91
 
92
+ # Check equality of the int32 with another object.
93
+ #
94
+ # @param [ Object ] other The object to check against.
95
+ #
96
+ # @return [ true, false ] If the objects are equal.
97
+ #
98
+ # @since 4.4.0
99
+ def ==(other)
100
+ return false unless other.is_a?(Int32)
101
+ @integer == other.instance_variable_get('@integer')
102
+ end
103
+ alias :eql? :==
104
+ alias :=== :==
105
+
93
106
  private
94
107
 
95
108
  def out_of_range!
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,8 +14,7 @@
14
14
 
15
15
  module BSON
16
16
 
17
- # Represents a $maxKey type, which compares less than any other value in the
18
- # specification.
17
+ # Represents int64 type.
19
18
  #
20
19
  # @see http://bsonspec.org/#/specification
21
20
  #
@@ -82,9 +81,23 @@ module BSON
82
81
  #
83
82
  # @since 4.2.0
84
83
  def to_bson_key(validating_keys = Config.validating_keys?)
85
- @integer.to_bson_key(validating_keys)
84
+ @integer
86
85
  end
87
86
 
87
+ # Check equality of the int64 with another object.
88
+ #
89
+ # @param [ Object ] other The object to check against.
90
+ #
91
+ # @return [ true, false ] If the objects are equal.
92
+ #
93
+ # @since 4.4.0
94
+ def ==(other)
95
+ return false unless other.is_a?(Int64)
96
+ @integer == other.instance_variable_get('@integer')
97
+ end
98
+ alias :eql? :==
99
+ alias :=== :==
100
+
88
101
  private
89
102
 
90
103
  def out_of_range!
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -156,7 +156,7 @@ module BSON
156
156
  #
157
157
  # @since 2.0.0
158
158
  def to_bson_key(validating_keys = Config.validating_keys?)
159
- to_s.to_bson_key(validating_keys)
159
+ self
160
160
  end
161
161
 
162
162
  private
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2016 MongoDB Inc.
1
+ # Copyright (C) 2016-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2016 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2009-2014 MongoDB Inc.
2
+ # Copyright (C) 2009-2019 MongoDB Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
1
+ # Copyright (C) 2009-2019 MongoDB Inc.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ module BSON
57
57
  #
58
58
  # @since 2.0.0
59
59
  def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
60
- to_s.to_bson(buffer)
60
+ buffer.put_symbol(self)
61
61
  end
62
62
 
63
63
  # Get the symbol as a BSON key name encoded C symbol.
@@ -71,7 +71,10 @@ module BSON
71
71
  #
72
72
  # @since 2.0.0
73
73
  def to_bson_key(validating_keys = Config.validating_keys?)
74
- to_s.to_bson_key(validating_keys)
74
+ if validating_keys
75
+ raise BSON::String::IllegalKey.new(self) if BSON::String::ILLEGAL_KEY =~ self
76
+ end
77
+ self
75
78
  end
76
79
 
77
80
  # Converts the symbol to a normalized key in a BSON document.