lib-bson 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/lib/bson/document.rb +48 -0
- data/lib/bson/version.rb +3 -0
- data/lib/lib-bson.rb +1 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4bd4b4519ac6cc488afab4b3682bc6fe853c34f07aadcf149613443bf7282dd9
|
4
|
+
data.tar.gz: 2a7bca7b453022badfc2ce7df8dc74eee4e779e3d3b13e74d1055cd860cfed34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96488f3e68394d51fe71e5c32cb0a834dab59d146177fb77d1faa053aea5c58e2e5d0bc8fef84496c2cfd47011977f4ac38072348d78726eb527d46e51f6a97b
|
7
|
+
data.tar.gz: 9a9cdcfb6e2d4104bee00dec53ea8f8a444de5731c2b48710ca817726eb1242f4b064e263395908743c3c9e44034df73c627b72ed8a41cddde5371ac1532cb32
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 fmjsjx
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module BSON
|
2
|
+
|
3
|
+
# Injects behaviour for BSON::Document.
|
4
|
+
#
|
5
|
+
# @since 1.0.0
|
6
|
+
class Document
|
7
|
+
|
8
|
+
# Retrieves the value object corresponding to the each key objects repeatedly.
|
9
|
+
# Will normalize symbol keys into strings.
|
10
|
+
# Will returns &block.call if the returned value is nil
|
11
|
+
#
|
12
|
+
# @since 1.0.0
|
13
|
+
def dig_or_get(*args, &block)
|
14
|
+
value = self.dig *args
|
15
|
+
if value.nil? && !block.nil?
|
16
|
+
value = block.call
|
17
|
+
end
|
18
|
+
value
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get embedded value.
|
22
|
+
#
|
23
|
+
# @since 1.0.0
|
24
|
+
def get_embedded(path, *args, &block)
|
25
|
+
keys = path.split '.'
|
26
|
+
value = self
|
27
|
+
keys.each do |key|
|
28
|
+
if value.is_a? BSON::Document
|
29
|
+
value = value[key]
|
30
|
+
elsif value.is_a? Array
|
31
|
+
if /^\d+$/.match key
|
32
|
+
value = value[key.to_i]
|
33
|
+
else
|
34
|
+
return block.nil? ? (args.empty? ? nil : args.first) : block.call
|
35
|
+
end
|
36
|
+
else
|
37
|
+
return block.nil? ? (args.empty? ? nil : args.first) : block.call
|
38
|
+
end
|
39
|
+
end
|
40
|
+
if value.nil?
|
41
|
+
return block.nil? ? (args.empty? ? nil : args.first) : block.call
|
42
|
+
end
|
43
|
+
return value
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/bson/version.rb
ADDED
data/lib/lib-bson.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'bson/document'
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lib-bson
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fang MinJie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: " Lib-BSON is a simple library aims to patch some useful functions
|
14
|
+
for BSON in RUBY.\n"
|
15
|
+
email:
|
16
|
+
- fmjsjx@163.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- lib/bson/document.rb
|
24
|
+
- lib/bson/version.rb
|
25
|
+
- lib/lib-bson.rb
|
26
|
+
homepage: https://github.com/fmjsjx/lib-bson
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.3.0
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubygems_version: 3.1.2
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Patch some useful functions for BSON in RUBY..
|
49
|
+
test_files: []
|