queryable_hash 0.0.1 → 0.0.2
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 +4 -4
- data/lib/queryable_hash/not_found_error.rb +4 -0
- data/lib/queryable_hash/version.rb +1 -1
- data/lib/queryable_hash/wrapper.rb +7 -2
- data/lib/queryable_hash.rb +1 -0
- data/test/wrapper_test.rb +20 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11acee1b3ab7cc1a5e72a3dd41e60237f35e4b48
|
4
|
+
data.tar.gz: cadeeaecf05682fd868c6d6bf7a80b7fa782d5a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d43064e8d08fd036bc796579dd748e918b39f7ec4219d75a0ae9a3507360385c311c3ef8f48651449c395ef61b972dc4a88dd3d3b5e35ad8b6630a5c7b55221
|
7
|
+
data.tar.gz: 01de95f0c6edc25d80f683f6b66a881cfc100f922a2705edf2fc9ed252f4c6d37baf02a13b4bd06bc77085a1014cddcc134d36d48e2808551e85adf71209cc04
|
@@ -19,13 +19,18 @@ module QueryableHash
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def find_first(*queries, nil_value: nil)
|
22
|
+
def find_first(*queries, nil_value: nil, raise_when_nil: false)
|
23
23
|
first = find_all(*queries, nil_value: nil_value).find do |result|
|
24
24
|
result != nil_value
|
25
25
|
end
|
26
|
-
first
|
26
|
+
first ||= nil_value
|
27
|
+
|
28
|
+
raise NotFoundError if raise_when_nil && first == nil_value
|
29
|
+
first
|
27
30
|
end
|
28
31
|
|
32
|
+
alias_method :find, :find_first
|
33
|
+
|
29
34
|
def to_hash
|
30
35
|
@original_hash
|
31
36
|
end
|
data/lib/queryable_hash.rb
CHANGED
data/test/wrapper_test.rb
CHANGED
@@ -49,6 +49,15 @@ module QueryableHash
|
|
49
49
|
assert @queryable.find_first(query) == "SGML"
|
50
50
|
end
|
51
51
|
|
52
|
+
test "find_first with multiple queries" do
|
53
|
+
result = @queryable.find_first(
|
54
|
+
"glossary.title",
|
55
|
+
"glossary.gloss_div.gloss_list.gloss_entry.gloss_term",
|
56
|
+
"glossary.gloss_div.gloss_list.gloss_entry.gloss_def.para"
|
57
|
+
)
|
58
|
+
assert result == "example glossary"
|
59
|
+
end
|
60
|
+
|
52
61
|
test "find_first with missing key" do
|
53
62
|
query = "this.key.does.not.exist"
|
54
63
|
assert @queryable.find_first(query).nil?
|
@@ -59,7 +68,7 @@ module QueryableHash
|
|
59
68
|
assert @queryable.find_first(query, nil_value: "missing") == "missing"
|
60
69
|
end
|
61
70
|
|
62
|
-
test "find_first with multiple queries" do
|
71
|
+
test "find_first with multiple queries some invalid" do
|
63
72
|
term = @queryable.find_first(
|
64
73
|
"glossary.div.list.entry.term",
|
65
74
|
"glossary.gloss_div.list.entry.term",
|
@@ -70,6 +79,16 @@ module QueryableHash
|
|
70
79
|
assert term == "Standard Generalized Markup Language"
|
71
80
|
end
|
72
81
|
|
82
|
+
test "find_first with raise" do
|
83
|
+
query = "nate.this.key.does.not.exist"
|
84
|
+
begin
|
85
|
+
@queryable.find_first(query, raise_when_nil: true)
|
86
|
+
rescue NotFoundError => e
|
87
|
+
end
|
88
|
+
|
89
|
+
assert e
|
90
|
+
end
|
91
|
+
|
73
92
|
test "to_hash" do
|
74
93
|
assert @queryable.to_hash == @data
|
75
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queryable_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- lib/queryable_hash.rb
|
91
|
+
- lib/queryable_hash/not_found_error.rb
|
91
92
|
- lib/queryable_hash/version.rb
|
92
93
|
- lib/queryable_hash/wrapper.rb
|
93
94
|
- test/test_helper.rb
|