dolly 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dolly/collection.rb +20 -0
- data/lib/dolly/version.rb +1 -1
- data/lib/exceptions/dolly.rb +1 -0
- data/test/collection_test.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b95a3057eeb5b34b96057f4275d05092a50691e1
|
4
|
+
data.tar.gz: 50b3dbc939e4d994c9ff882cb89299552236a1ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a76f4783159796be1d936fde1612a45ba2a8855224a08adf72af6450fa325d23b510472b51f67bc772ed03617139e78845d306bf524ac4ce8bd7a6891ec3c70d
|
7
|
+
data.tar.gz: 1d050ebc067d3df4f72e89b8d1eaa17519ce20130c061980451e0bf8e2a6749c52901c97117a008b40d8f1245852ae402705f92809bfba0dfb7614d3c45133ce
|
data/lib/dolly/collection.rb
CHANGED
@@ -20,6 +20,26 @@ module Dolly
|
|
20
20
|
to_a.last
|
21
21
|
end
|
22
22
|
|
23
|
+
def update_properties! properties ={}
|
24
|
+
properties.each do |key, value|
|
25
|
+
|
26
|
+
regex = %r{
|
27
|
+
\"#{key}\": # find key definition in json string
|
28
|
+
( # start value group
|
29
|
+
\"[^\"]*\" # find anything (even empty) between \" and \"
|
30
|
+
| # logical OR
|
31
|
+
null #literal null value
|
32
|
+
) # end value group
|
33
|
+
}x
|
34
|
+
|
35
|
+
raise Dolly::MissingPropertyError unless json.match regex
|
36
|
+
json.gsub! regex, "\"#{key}\":\"#{value}\""
|
37
|
+
end
|
38
|
+
|
39
|
+
BulkDocument.new(Dolly::Document.database, to_a).save
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
23
43
|
def map &block
|
24
44
|
load if empty?
|
25
45
|
@set.collect &block
|
data/lib/dolly/version.rb
CHANGED
data/lib/exceptions/dolly.rb
CHANGED
data/test/collection_test.rb
CHANGED
@@ -37,4 +37,23 @@ class CollectionTest < ActiveSupport::TestCase
|
|
37
37
|
assert_equal ["Foo B", "Foo A"], @collection.map(&:foo)
|
38
38
|
end
|
39
39
|
|
40
|
+
test 'update attributes will change expected attributes' do
|
41
|
+
@collection.update_properties! foo: 'Foo 4 All'
|
42
|
+
assert_equal ['Foo 4 All', 'Foo 4 All'], @collection.map(&:foo)
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'update empty attributes' do
|
46
|
+
json = '{"total_rows":2,"offset":0,"rows":[{"id":"foo_bar/0","key":"foo_bar","value":1,"doc":{"_id":"foo_bar/0","_rev":"7f66379ac92eb6dfafa50c94bd795122","foo":null,"bar":"","type":"foo_bar"}},{"id":"foo_bar/1","key":"foo_bar","value":1,"doc":{"_id":"foo_bar/1","_rev":"4d33cea0e55142c9ecc6a81600095469","foo":"Foo A","bar":"Bar A","type":"foo_bar"}}]}'
|
47
|
+
collection = Dolly::Collection.new json, FooBar
|
48
|
+
|
49
|
+
collection.update_properties! foo: 'Foo 4 All', bar: 'stuff'
|
50
|
+
assert_equal ['Foo 4 All', 'Foo 4 All'], collection.map(&:foo)
|
51
|
+
assert_equal ['stuff', 'stuff'], collection.map(&:bar)
|
52
|
+
end
|
53
|
+
|
54
|
+
test 'ypdate attributes will raise exception if property is missing' do
|
55
|
+
assert_raise Dolly::MissingPropertyError do
|
56
|
+
@collection.update_properties! missing: 'Ha! Ha!'
|
57
|
+
end
|
58
|
+
end
|
40
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dolly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- javierg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|