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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84427d100a7c6e64e513b120537d2347cae31bcb08f2d9270d46946f0cecab6f
4
- data.tar.gz: 9bfb6408d1c44c3ff4cc25de3beaeb37cbd5ff18d271c44af989b37f050760f6
3
+ metadata.gz: f7ebc610124815bfa5709c7bb80cf0e6820ab80737c0e78dd905a75a7415cbc7
4
+ data.tar.gz: 2fc625c003435db82bff2a00875d8227660b0b9f7bd7ab846c12a6d7f9d320aa
5
5
  SHA512:
6
- metadata.gz: fb891b58d7763ad8a26858941a8067fa601db56cdef379f5a56fb59de1c25851d98cbf4653fb592bba985717d1e06f85681138979e9a061ab91cb1ea186dd4c2
7
- data.tar.gz: b33f84f1c0b06b0c5c1095bf6fa047d066ba3be9ca2f1cb7860bfab3c8a36066b84be74a61cc539500f0eeb30bba441ec4ba213e24fb004379f47b918d133a14
6
+ metadata.gz: 81fddb7de7af2cc27e109c4bf7b2c966ff19ab8d0840a4162aa1bc7cd31c71213c7aba6932dd552d1820d2d5979e0f5f70e3d1960efdeec6f49f9e1ddc2109a7
7
+ data.tar.gz: e936607ffc4e3cf15c9aa494d55ce5ff8197d60562820b185e4e9ade7146c359820bc4ad9d92ded1d3a96c48a5a427b37f76fd9ffd4dfb87251d70175895ac49
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-2016 MongoDB Inc.
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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2016 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,5 +1,5 @@
1
1
  /*
2
- * Copyright 2015-2016 MongoDB, Inc.
2
+ * Copyright 2015-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.
@@ -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
- super(convert_key(key))
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
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module BSON
16
- VERSION = "4.4.1".freeze
16
+ VERSION = "4.4.2".freeze
17
17
  end
@@ -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
 
@@ -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.
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.1
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-17 00:00:00.000000000 Z
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 License Version 2.0
165
+ - Apache-2.0
166
166
  metadata: {}
167
167
  post_install_message:
168
168
  rdoc_options: []
metadata.gz.sig CHANGED
Binary file