babl-json 0.5.4 → 0.5.5

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: 310b4377dc2e8962bd245804fd9ca8ede567748a
4
- data.tar.gz: 39aa36ae900752cabc18f484d1dc047439f60391
3
+ metadata.gz: 06e7d0d6838bd28a3c50434afec9a7ef3673f659
4
+ data.tar.gz: 8e4d913e0e5b97e9280a2535543a73c069e2cf84
5
5
  SHA512:
6
- metadata.gz: 88716be5c080dd4a545234561898aa6c6ae63194d3b5be8de37721a2473934b185ba2f7bb0accf07a811111250c07fd05ffbab2838bda63dbb1e79e9c11bef59
7
- data.tar.gz: 7a993254d2dede29615e414a9c82ad1d3023a03aeecd1d6ba512bf3465d61f7f1f2d2addc1ca8c0758e9c11cab9aa356b21ec2276a36e4730a0dd27aaf525d23
6
+ metadata.gz: eb6f0a919e68efd724dffbe3ffccdda0b48a780dc73e41b50c963868d7c1ce5ca92d3935f1566eeeff1e02e9f1d8a3ec8627aba46cc052dbc69052b50de5596c
7
+ data.tar.gz: 263c993251039ad9266380382ad0b41206eed7b554cb917aae4b70b5d693a8246ac249201cc7b8df51567f6ecade0775d5981cf92460430c794f6cad2d87736d
@@ -7,11 +7,11 @@ module Babl
7
7
  module Nodes
8
8
  class Concat < Utils::Value.new(:nodes)
9
9
  def dependencies
10
- nodes.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
10
+ Babl::Utils::Hash.deep_merge(*nodes.map(&:dependencies))
11
11
  end
12
12
 
13
13
  def pinned_dependencies
14
- nodes.map(&:pinned_dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
14
+ Babl::Utils::Hash.deep_merge(*nodes.map(&:pinned_dependencies))
15
15
  end
16
16
 
17
17
  def schema
@@ -8,7 +8,7 @@ module Babl
8
8
  class Each < Utils::Value.new(:node)
9
9
  def dependencies
10
10
  node_deps = node.dependencies
11
- child_deps = node.dependencies.reject { |key, _| key == Parent::PARENT_MARKER }
11
+ child_deps = node_deps.reject { |key, _| key == Parent::PARENT_MARKER }
12
12
 
13
13
  Babl::Utils::Hash.deep_merge(
14
14
  node_deps[Parent::PARENT_MARKER] || Utils::Hash::EMPTY,
@@ -13,11 +13,11 @@ module Babl
13
13
  end
14
14
 
15
15
  def dependencies
16
- nodes.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
16
+ Babl::Utils::Hash.deep_merge(*nodes.map(&:dependencies))
17
17
  end
18
18
 
19
19
  def pinned_dependencies
20
- nodes.map(&:pinned_dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
20
+ Babl::Utils::Hash.deep_merge(*nodes.map(&:pinned_dependencies))
21
21
  end
22
22
 
23
23
  def render(frame)
@@ -8,11 +8,11 @@ module Babl
8
8
  module Nodes
9
9
  class Merge < Utils::Value.new(:nodes)
10
10
  def dependencies
11
- nodes.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
11
+ Babl::Utils::Hash.deep_merge(*nodes.map(&:dependencies))
12
12
  end
13
13
 
14
14
  def pinned_dependencies
15
- nodes.map(&:pinned_dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
15
+ Babl::Utils::Hash.deep_merge(*nodes.map(&:pinned_dependencies))
16
16
  end
17
17
 
18
18
  def schema
@@ -8,7 +8,7 @@ module Babl
8
8
  class Nav < Utils::Value.new(:property, :node)
9
9
  def dependencies
10
10
  node_deps = node.dependencies
11
- child_deps = node.dependencies.reject { |key, _| key == Parent::PARENT_MARKER }
11
+ child_deps = node_deps.reject { |key, _| key == Parent::PARENT_MARKER }
12
12
 
13
13
  Babl::Utils::Hash.deep_merge(
14
14
  node_deps[Parent::PARENT_MARKER] || Utils::Hash::EMPTY,
@@ -9,12 +9,11 @@ module Babl
9
9
  EMPTY = new(Utils::Hash::EMPTY)
10
10
 
11
11
  def dependencies
12
- nodes.values.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
12
+ Babl::Utils::Hash.deep_merge(*nodes.values.map(&:dependencies))
13
13
  end
14
14
 
15
15
  def pinned_dependencies
16
- nodes.values.map(&:pinned_dependencies)
17
- .reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
16
+ Babl::Utils::Hash.deep_merge(*nodes.values.map(&:pinned_dependencies))
18
17
  end
19
18
 
20
19
  def schema
@@ -14,13 +14,11 @@ module Babl
14
14
  end
15
15
 
16
16
  def dependencies
17
- nodes.flatten(1).map(&:dependencies)
18
- .reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
17
+ Babl::Utils::Hash.deep_merge(*nodes.flatten(1).map(&:dependencies))
19
18
  end
20
19
 
21
20
  def pinned_dependencies
22
- nodes.flatten(1).map(&:pinned_dependencies)
23
- .reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
21
+ Babl::Utils::Hash.deep_merge(*nodes.flatten(1).map(&:pinned_dependencies))
24
22
  end
25
23
 
26
24
  def schema
@@ -11,16 +11,13 @@ module Babl
11
11
 
12
12
  def dependencies
13
13
  Babl::Utils::Hash.deep_merge(
14
- node.dependencies[Parent::PARENT_MARKER] || Utils::Hash::EMPTY,
15
- nodes.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b|
16
- Babl::Utils::Hash.deep_merge(a, b)
17
- }
14
+ *nodes.map(&:dependencies),
15
+ node.dependencies[Parent::PARENT_MARKER] || Utils::Hash::EMPTY
18
16
  )
19
17
  end
20
18
 
21
19
  def pinned_dependencies
22
- (nodes + [node]).map(&:pinned_dependencies)
23
- .reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
20
+ Babl::Utils::Hash.deep_merge(*(nodes + [node]).map(&:pinned_dependencies))
24
21
  end
25
22
 
26
23
  def render(frame)
@@ -4,10 +4,16 @@ module Babl
4
4
  class Hash
5
5
  EMPTY = {}.freeze
6
6
 
7
- # Source: http://stackoverflow.com/a/9381776/1434017 (Jon M)
8
- def self.deep_merge(first, second)
9
- merger = proc { |_key, v1, v2| ::Hash === v1 && ::Hash === v2 ? v1.merge(v2, &merger) : v2 }
10
- first.merge(second, &merger)
7
+ def self.deep_merge(*hashes)
8
+ filtered_hashes = hashes.reject(&:empty?)
9
+ return EMPTY if filtered_hashes.empty?
10
+ return filtered_hashes.first if filtered_hashes.size == 1
11
+ filtered_hashes.reduce({}) { |out, hash| deep_merge_inplace(out, hash) }
12
+ end
13
+
14
+ def self.deep_merge_inplace(target, source)
15
+ source.each { |k, v| target[k] = deep_merge_inplace(target[k] || {}, v) }
16
+ target
11
17
  end
12
18
  end
13
19
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Babl
3
- VERSION = '0.5.4'
3
+ VERSION = '0.5.5'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: babl-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederic Terrazzoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-29 00:00:00.000000000 Z
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls