bson 4.4.1 → 4.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +1 -1
- data/ext/bson/bson_native.c +1 -1
- data/ext/bson/native-endian.h +1 -1
- data/lib/bson/document.rb +22 -4
- data/lib/bson/version.rb +1 -1
- data/spec/bson/document_spec.rb +32 -0
- data/spec/support/common_driver.rb +1 -1
- data/spec/support/corpus.rb +1 -1
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7ebc610124815bfa5709c7bb80cf0e6820ab80737c0e78dd905a75a7415cbc7
|
4
|
+
data.tar.gz: 2fc625c003435db82bff2a00875d8227660b0b9f7bd7ab846c12a6d7f9d320aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81fddb7de7af2cc27e109c4bf7b2c966ff19ab8d0840a4162aa1bc7cd31c71213c7aba6932dd552d1820d2d5979e0f5f70e3d1960efdeec6f49f9e1ddc2109a7
|
7
|
+
data.tar.gz: e936607ffc4e3cf15c9aa494d55ce5ff8197d60562820b185e4e9ade7146c359820bc4ad9d92ded1d3a96c48a5a427b37f76fd9ffd4dfb87251d70175895ac49
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ As of 2.0.0, this project adheres to the [Semantic Versioning Specification](htt
|
|
32
32
|
License
|
33
33
|
-------
|
34
34
|
|
35
|
-
Copyright (C) 2009-
|
35
|
+
Copyright (C) 2009-2019 MongoDB Inc.
|
36
36
|
|
37
37
|
Licensed under the Apache License, Version 2.0 (the "License");
|
38
38
|
you may not use this file except in compliance with the License.
|
data/ext/bson/bson_native.c
CHANGED
data/ext/bson/native-endian.h
CHANGED
data/lib/bson/document.rb
CHANGED
@@ -37,19 +37,37 @@ module BSON
|
|
37
37
|
# Get a value from the document for the provided key. Can use string or
|
38
38
|
# symbol access, with string access being the faster of the two.
|
39
39
|
#
|
40
|
+
# @overload fetch(key)
|
41
|
+
# Returns a value from the hash for the given key. If the key does
|
42
|
+
# not exist, raises KeyError exception.
|
43
|
+
#
|
44
|
+
# @overload fetch(key, default)
|
45
|
+
# Returns a value from the hash for the given key. If the key does not
|
46
|
+
# exist, returns *default*.
|
47
|
+
#
|
48
|
+
# @overload fetch(key, &block)
|
49
|
+
# Returns a value from the hash for the given key. If the key does not
|
50
|
+
# exist, returns the value of the block called with the key.
|
51
|
+
#
|
40
52
|
# @example Get an element for the key.
|
41
53
|
# document.fetch("field")
|
42
54
|
#
|
43
|
-
# @example Get an element for the key by symbol.
|
44
|
-
# document.fetch(:field)
|
55
|
+
# @example Get an element for the key by symbol with a default.
|
56
|
+
# document.fetch(:field, 'foo')
|
57
|
+
#
|
58
|
+
# @example Get an element for the key by symbol with a block default.
|
59
|
+
# document.fetch(:field) { |key| key.upcase }
|
45
60
|
#
|
46
61
|
# @param [ String, Symbol ] key The key to look up.
|
62
|
+
# @param [ Object ] default Returned value if key does not exist.
|
63
|
+
# @yield [key] Block returning default value for the given key.
|
47
64
|
#
|
48
65
|
# @return [ Object ] The found value. Raises KeyError if none found.
|
49
66
|
#
|
50
67
|
# @since 4.4.0
|
51
|
-
def fetch(key)
|
52
|
-
|
68
|
+
def fetch(key, *args, &block)
|
69
|
+
key = convert_key(key)
|
70
|
+
super(key, *args, &block)
|
53
71
|
end
|
54
72
|
|
55
73
|
# Get a value from the document for the provided key. Can use string or
|
data/lib/bson/version.rb
CHANGED
data/spec/bson/document_spec.rb
CHANGED
@@ -76,6 +76,38 @@ describe BSON::Document do
|
|
76
76
|
document.fetch(:non_existent_key)
|
77
77
|
end.to raise_exception(KeyError)
|
78
78
|
end
|
79
|
+
|
80
|
+
context "and default value is provided" do
|
81
|
+
|
82
|
+
it "returns default value" do
|
83
|
+
expect(document.fetch(:non_existent_key, false)).to eq(false)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "and block is passed" do
|
88
|
+
|
89
|
+
it "returns result of the block" do
|
90
|
+
expect(document.fetch(:non_existent_key, &:to_s))
|
91
|
+
.to eq("non_existent_key")
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when key exists" do
|
97
|
+
|
98
|
+
context "and default value is provided" do
|
99
|
+
|
100
|
+
it "returns the value" do
|
101
|
+
expect(document.fetch(:key, "other")).to eq("value")
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "and block is passed" do
|
106
|
+
|
107
|
+
it "returns the value" do
|
108
|
+
expect(document.fetch(:key, &:to_s)).to eq("value")
|
109
|
+
end
|
110
|
+
end
|
79
111
|
end
|
80
112
|
end
|
81
113
|
|
data/spec/support/corpus.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.4.
|
4
|
+
version: 4.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Brock
|
@@ -33,7 +33,7 @@ cert_chain:
|
|
33
33
|
bMYVwXXhV8czdzgkQB/ZPWHSbEWXnmkze1mzvqWBCPOVXYrcnL9cnEl/RoxtS1hr
|
34
34
|
Db6Ac6mCUSYfYHBWpWqxjc45n70i5Xi1
|
35
35
|
-----END CERTIFICATE-----
|
36
|
-
date: 2019-01-
|
36
|
+
date: 2019-01-22 00:00:00.000000000 Z
|
37
37
|
dependencies: []
|
38
38
|
description: A full featured BSON specification implementation, in Ruby
|
39
39
|
email:
|
@@ -162,7 +162,7 @@ files:
|
|
162
162
|
- spec/support/spec_config.rb
|
163
163
|
homepage: http://bsonspec.org
|
164
164
|
licenses:
|
165
|
-
- Apache
|
165
|
+
- Apache-2.0
|
166
166
|
metadata: {}
|
167
167
|
post_install_message:
|
168
168
|
rdoc_options: []
|
metadata.gz.sig
CHANGED
Binary file
|