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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1273b083d974c464f726e6510178f8eaeddcf1cc
4
- data.tar.gz: f35313f862feeaa8f5e1cffa5a034c8cc419a854
3
+ metadata.gz: dcc9d99d779d2fd025adee3e0eb753f1427f4213
4
+ data.tar.gz: 3bef0178a6814c6be3cff4612bd3af48db9fa934
5
5
  SHA512:
6
- metadata.gz: 399c3832571dd080b208d3fcdf610dbfbe530e5d089ad33a35580707cb0ff6bb1fb66e2778c1dbde0135e4fc17ecc74c161b4cbbb5cf70a726b99416a19d789f
7
- data.tar.gz: 55eca025ae4b0bc64034eebec3be716b30b18dd9718100fd90792321656c98e682d0a61a8c664c9af9c57bf57e77d399dc79c46e61aa159ce45a1d2cc99cd40b
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."
@@ -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
@@ -2,7 +2,7 @@ module Beret
2
2
 
3
3
  VERSION = [
4
4
  0, # major
5
- 4, # minor
5
+ 5, # minor
6
6
  0 # patch
7
7
  ].join('.')
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beret
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lawson Kurtz (Viget)