dolly 1.1.1 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a752e24460e1d6fc8cf00c9559af2f2be244387d
4
- data.tar.gz: 21094c71f3df84d38d8eb86da5e46f3c70001fb0
3
+ metadata.gz: b95a3057eeb5b34b96057f4275d05092a50691e1
4
+ data.tar.gz: 50b3dbc939e4d994c9ff882cb89299552236a1ce
5
5
  SHA512:
6
- metadata.gz: 2cbeb233b8c84f344130f593718903d2386b3713f75f6ada4d215cc5220b67c11b53e62933e4c327884c2fcae1cd1fc98301d2591eaf33de74906b6d055bd193
7
- data.tar.gz: 2d417e18b9147627481684279ed654f1b624e2ec34ab00e4221381e0dac82e856b9319511b4c5481a97dcc7da831062d45004225281729604b16238c2133acfd
6
+ metadata.gz: a76f4783159796be1d936fde1612a45ba2a8855224a08adf72af6450fa325d23b510472b51f67bc772ed03617139e78845d306bf524ac4ce8bd7a6891ec3c70d
7
+ data.tar.gz: 1d050ebc067d3df4f72e89b8d1eaa17519ce20130c061980451e0bf8e2a6749c52901c97117a008b40d8f1245852ae402705f92809bfba0dfb7614d3c45133ce
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dolly
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -34,4 +34,5 @@ module Dolly
34
34
  end
35
35
  end
36
36
  class DocumentInvalidError < RuntimeError; end
37
+ class MissingPropertyError < RuntimeError; end
37
38
  end
@@ -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.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-21 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties