dbla 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dbla/document.rb +3 -2
- data/lib/dbla/version.rb +1 -1
- data/spec/unit/document_spec.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a9d166f21b64fbaab705cec213e50b94aeb253e
|
4
|
+
data.tar.gz: 4669e265f650ec57bb0d5d3323f3ea6b488c5c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce5c08a0345ff246d42fb7cc196bd9afe6506f3e35a5a666327bb5f363a4780fb2b7558ec80d006bd0cf8f3a077ee70b16288ae5ee2d5edccb7181f54266ca8a
|
7
|
+
data.tar.gz: 837cdd286e978c92fb832b1fa3eed7c881a8c8513542936015334162d12ef018c7a95ceec16bf41a5fadb1ae539ae81decd1d63b8b96cf84cfc001753d76b1f3
|
data/lib/dbla/document.rb
CHANGED
@@ -4,7 +4,7 @@ module Dbla
|
|
4
4
|
def [] *args
|
5
5
|
if args.first && args.first.to_s.index('.')
|
6
6
|
keys = args.first.to_s.split('.')
|
7
|
-
keys.inject(_source) do |m,key|
|
7
|
+
r = keys.inject(_source) do |m,key|
|
8
8
|
# Array() has a special behavior we do not want for hashes
|
9
9
|
m = (m.is_a? Array) ? m : [m]
|
10
10
|
m.inject([]) do |m2, a|
|
@@ -22,12 +22,13 @@ module Dbla
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
+
r.blank? ? nil : r
|
25
26
|
else
|
26
27
|
_source.send :[], *args
|
27
28
|
end
|
28
29
|
end
|
29
30
|
def fetch(field, default)
|
30
|
-
(r = self[field]).
|
31
|
+
(r = self[field]).blank? ? default : r
|
31
32
|
end
|
32
33
|
def has? f, *values
|
33
34
|
if values.empty?
|
data/lib/dbla/version.rb
CHANGED
data/spec/unit/document_spec.rb
CHANGED
@@ -24,9 +24,11 @@ describe Dbla::Document do
|
|
24
24
|
describe "[]" do
|
25
25
|
it do
|
26
26
|
expect(subject['foo']).to eql('bar')
|
27
|
+
expect(subject['fob']).to eql(nil)
|
27
28
|
expect(subject['lol']).to eql(['wut', 'no'])
|
28
29
|
expect(subject['o.hai.rly']).to eql(['yarly','norly'])
|
29
|
-
expect(subject['o.hai.wut']).to eql(
|
30
|
+
expect(subject['o.hai.wut']).to eql(nil)
|
31
|
+
expect(subject['p.hai.wut']).to eql(nil)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
describe "fetch" do
|
@@ -37,10 +39,12 @@ describe Dbla::Document do
|
|
37
39
|
describe "has?" do
|
38
40
|
it "should work with only a key" do
|
39
41
|
expect(subject.has? 'foo').to eql(true)
|
42
|
+
expect(subject.has? 'fob').to eql(false)
|
40
43
|
expect(subject.has? 'o.hai.rly').to eql(true)
|
41
44
|
expect(subject.has? 'o.hai.rly','norly').to eql(true)
|
42
45
|
expect(subject.has? 'o.hai.rly','gnarly').to eql(false)
|
43
46
|
expect(subject.has? 'o.hai.wut').to eql(false)
|
47
|
+
expect(subject.has? 'p.hai.wut').to eql(false)
|
44
48
|
end
|
45
49
|
it "should work with a value" do
|
46
50
|
end
|