beret 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6490a904f8d44b4742981355f88f276ffc6b15cf
4
- data.tar.gz: 2f242277dc37205dfe6ea83831dd37e472fd5ff5
3
+ metadata.gz: 1273b083d974c464f726e6510178f8eaeddcf1cc
4
+ data.tar.gz: f35313f862feeaa8f5e1cffa5a034c8cc419a854
5
5
  SHA512:
6
- metadata.gz: 73920e909c96e1aecca8d5b1f5c7611ad8a2495e78a578f2a9dd7825ac8f7104f979af9464f9ee37c52a17397ce1ecc3d87d3cc083d34e3f6c6bff653a0a56ad
7
- data.tar.gz: 6dc79c0ce717b81d84b67c23530de3ab3121cd2d296c638be8664e346c8d6f1ab3b97a653363bd161057fa75cc92bd1c635984913962353ba94a710468dd1a18
6
+ metadata.gz: 399c3832571dd080b208d3fcdf610dbfbe530e5d089ad33a35580707cb0ff6bb1fb66e2778c1dbde0135e4fc17ecc74c161b4cbbb5cf70a726b99416a19d789f
7
+ data.tar.gz: 55eca025ae4b0bc64034eebec3be716b30b18dd9718100fd90792321656c98e682d0a61a8c664c9af9c57bf57e77d399dc79c46e61aa159ce45a1d2cc99cd40b
data/README.md CHANGED
@@ -31,17 +31,33 @@ ck_json = "[{\"content\":{\"text\":\"This is some text.\"},\"type\":\"redactor\"
31
31
  beret = Beret.new(ck_json)
32
32
 
33
33
  # Finding values
34
- beret.find(:photo_id) # => [<Beret::Result value="42">, <Beret::Result value="144">]
35
- beret.find(:photo_id, in: [:image]) # => [<Beret::Result value="42">]
36
- beret.find(:photo_id, in: [:avatar]) # => [<Beret::Result value="144">]
34
+ beret.find(:photo_id) # => [<Beret::SearchResult value="42">, <Beret::SearchResult value="144">]
35
+ beret.find(:photo_id, in: [:image]) # => [<Beret::SearchResult value="42">]
36
+ beret.find(:photo_id, in: [:avatar]) # => [<Beret::SearchResult value="144">]
37
37
  beret.find(:photo_id, in: [:some_other_block_type]) # => []
38
38
 
39
+ # Using SearchResult objects
40
+ result = beret.find(:photo_id).first
41
+ result.value # => "42"
42
+ result.field_name # => "photo_id"
43
+ result.block # => <Beret::Block>
44
+ result.block.attributes # => { "photo_id" => "42" }
45
+ result.block.type # => "image"
46
+ result.block.parent # => <Beret::Block>
47
+
39
48
  # In-place updating
40
- beret.update(:photo_id, in: [:image]) do |value|
49
+ beret.update(:photo_id, in: [:image]) do |value, block|
41
50
  # Transform the value any way you'd like here.
42
51
  # In this example, we convert a plain old ID to a SGID
43
52
  Image.find(value).to_sgid
44
53
  end
45
54
 
46
- # Retrieving JSON
55
+ beret.update(:photo_id, in: [:image]) do |value, block|
56
+ # You can also replace the contents of an entire block with
57
+ # Beret::Block#update_content
58
+ image = Image.find(value)
59
+ block.update_content(image.to_json)
60
+ end
61
+
62
+ # Retrieving JSON (useful for saving or returning the net result of an in-place update)
47
63
  beret.to_json
data/lib/beret/block.rb CHANGED
@@ -19,6 +19,10 @@ module Beret
19
19
  @attributes[field_name.to_s] = value
20
20
  end
21
21
 
22
+ def update_content(new_content)
23
+ @attributes = Hash(new_content)
24
+ end
25
+
22
26
  def type
23
27
  block_json[type_key]
24
28
  end
@@ -13,7 +13,7 @@ module Beret
13
13
  results = find(field_name, options)
14
14
 
15
15
  results.each do |result|
16
- new_value = yield result.value
16
+ new_value = yield result.value, result.block
17
17
  result.block.update_attribute(field_name, new_value)
18
18
  end
19
19
  end
data/lib/beret/version.rb CHANGED
@@ -2,7 +2,7 @@ module Beret
2
2
 
3
3
  VERSION = [
4
4
  0, # major
5
- 3, # minor
5
+ 4, # minor
6
6
  0 # patch
7
7
  ].join('.')
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lawson Kurtz (Viget)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily work with Colonel Kurtz-generated JSON data in your Ruby application
14
14
  email: