beret 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/lib/beret.rb +1 -1
- data/lib/beret/block_set.rb +9 -1
- data/lib/beret/version.rb +1 -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: dcc9d99d779d2fd025adee3e0eb753f1427f4213
|
4
|
+
data.tar.gz: 3bef0178a6814c6be3cff4612bd3af48db9fa934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4398e35b50f0f8059ef556da225be5b0a3c7d9c804d93fa6e2286b448622c666ab98160ac0d87bc079fb192cb326aae5fb359e9aafea69d23610b7dea45f1267
|
7
|
+
data.tar.gz: b90caef5964124db64d08cbeca4484f41e4eb2037fdf74802ff1cd19c06129951826b6ecb4040a84fd205bc15376dc6ee364221fb6b9a7b75d265a334805bc1a
|
data/README.md
CHANGED
@@ -45,6 +45,13 @@ result.block.attributes # => { "photo_id" => "42" }
|
|
45
45
|
result.block.type # => "image"
|
46
46
|
result.block.parent # => <Beret::Block>
|
47
47
|
|
48
|
+
beret.find(:photo_id, in: [:image]) do |value, block|
|
49
|
+
# You can also replace the contents of an entire block with
|
50
|
+
# Beret::Block#update_content
|
51
|
+
image = Image.find(value)
|
52
|
+
block.update_content(image.to_json)
|
53
|
+
end
|
54
|
+
|
48
55
|
# In-place updating
|
49
56
|
beret.update(:photo_id, in: [:image]) do |value, block|
|
50
57
|
# Transform the value any way you'd like here.
|
@@ -52,12 +59,5 @@ beret.update(:photo_id, in: [:image]) do |value, block|
|
|
52
59
|
Image.find(value).to_sgid
|
53
60
|
end
|
54
61
|
|
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
62
|
# Retrieving JSON (useful for saving or returning the net result of an in-place update)
|
63
63
|
beret.to_json
|
data/lib/beret.rb
CHANGED
@@ -8,7 +8,7 @@ require "beret/block_set"
|
|
8
8
|
|
9
9
|
module Beret
|
10
10
|
def self.new(json)
|
11
|
-
array = JSON.parse(json)
|
11
|
+
array = json.kind_of?(Array) ? json : JSON.parse(json)
|
12
12
|
Beret::BlockSet.new(array)
|
13
13
|
rescue JSON::ParserError
|
14
14
|
raise "String provided to Beret.new() was not valid JSON."
|
data/lib/beret/block_set.rb
CHANGED
@@ -6,7 +6,15 @@ module Beret
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def find(field_name, options={})
|
9
|
-
Search.new(blocks, field_name, options).results
|
9
|
+
results = Search.new(blocks, field_name, options).results
|
10
|
+
|
11
|
+
if block_given?
|
12
|
+
results.each do |result|
|
13
|
+
yield result.value, result.block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
results
|
10
18
|
end
|
11
19
|
|
12
20
|
def update(field_name, options={})
|
data/lib/beret/version.rb
CHANGED