dentaku 3.4.0 → 3.4.1

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
  SHA256:
3
- metadata.gz: 1eb86933b899627333d93e993cd2d093a11f4ca54b2e0f6668c3580a8f133975
4
- data.tar.gz: 004bd53fa5c3c6815bafdbf98788de96757b688a6ba217b7f8e96be31a4f7d5d
3
+ metadata.gz: 0275b981a44fdb17f4eb1ec144c57baf3f5ab46f0bf65c6f98dda51b3bc80658
4
+ data.tar.gz: b5120974bd987a35e5388a5932e0a01d9a0d05692df9d0281d65ad729484754c
5
5
  SHA512:
6
- metadata.gz: 32f0e44638fc3738a3df5ba6a04abdb4ee66177049242260e26fea1ad6844a66a35e65ca5a27448f118838e6ccecd133f46650e9fbff5d878bbc14b1e7d952e8
7
- data.tar.gz: 8081bcf51e30daa33dbaba3f8796951151c1bfd2e3975f63e5291aac7e04e09f2fc2f00aa956cfdad99caf1b8a8fb4f04b2c0789d8909b0982372e75dc7f7fc0
6
+ metadata.gz: 76f427ebaed43836b95201f5939c90d3391b9887a7bfbbc3fc51973a7fdf7c25453be641fba639480e095284af26391437b5711731625e211ccf55cd616967c2
7
+ data.tar.gz: 6934989420f0c0d86914bcd10c2f562c138e883b3bb4b0d33013553f2403d45064b472932d069d79cb69c82c24a672668b50cc46fbca7740e2bf71982913635c
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ ## [v3.4.1] 2020-12-12
4
+ - prevent extra evaluations in bulk expression solver
5
+
3
6
  ## [v3.4.0] 2020-12-07
4
7
  - allow access to intermediate values of flattened hashes
5
8
  - catch invalid array syntax in the parse phase
@@ -12,6 +15,7 @@
12
15
  - add enum functions `ANY`, `ALL`, `MAP` and `PLUCK`
13
16
  - allow self-referential formulas in bulk expression solver
14
17
  - misc internal fixes and enhancements
18
+
15
19
  ## [v3.3.4] 2019-11-21
16
20
  - bugfix release
17
21
 
@@ -199,6 +203,7 @@
199
203
  ## [v0.1.0] 2012-01-20
200
204
  - initial release
201
205
 
206
+ [HEAD]: https://github.com/rubysolo/dentaku/compare/v3.4.0...v3.4.1
202
207
  [v3.4.0]: https://github.com/rubysolo/dentaku/compare/v3.3.4...v3.4.0
203
208
  [v3.3.4]: https://github.com/rubysolo/dentaku/compare/v3.3.3...v3.3.4
204
209
  [v3.3.3]: https://github.com/rubysolo/dentaku/compare/v3.3.2...v3.3.3
@@ -61,17 +61,19 @@ module Dentaku
61
61
  .transform_values { |v| calculator.ast(v) }
62
62
  .partition { |_, v| calculator.dependencies(v, nil).empty? }
63
63
 
64
- context = calculator.memory.merge(facts.to_h.each_with_object({}) do |(var_name, ast), h|
64
+ evaluated_facts = facts.to_h.each_with_object({}) do |(var_name, ast), h|
65
65
  with_rescues(var_name, h, block) do
66
66
  h[var_name] = ast.is_a?(Array) ? ast.map(&:value) : ast.value
67
67
  end
68
- end)
68
+ end
69
+
70
+ context = calculator.memory.merge(evaluated_facts)
69
71
 
70
72
  variables_in_resolve_order.each_with_object({}) do |var_name, results|
71
73
  next if expressions[var_name].nil?
72
74
 
73
75
  with_rescues(var_name, results, block) do
74
- results[var_name] = calculator.evaluate!(
76
+ results[var_name] = evaluated_facts[var_name] || calculator.evaluate!(
75
77
  expressions[var_name],
76
78
  context.merge(results),
77
79
  &expression_with_exception_handler(&block)
@@ -1,3 +1,3 @@
1
1
  module Dentaku
2
- VERSION = "3.4.0"
2
+ VERSION = "3.4.1"
3
3
  end
@@ -56,6 +56,16 @@ RSpec.describe Dentaku::BulkExpressionSolver do
56
56
  expect(solver.solve!).to eq(x: 6, y: 12) # x = 6 by the time y is calculated
57
57
  end
58
58
 
59
+ it "does not execute functions unnecessarily" do
60
+ calls = 0
61
+ external = ->() { calls += 1 }
62
+ hash = {test: 'EXTERNAL()'}
63
+ calculator = Dentaku::Calculator.new
64
+ calculator.add_function(:external, :numeric, external)
65
+ calculator.solve(hash)
66
+ expect(calls).to eq(1)
67
+ end
68
+
59
69
  it "evaluates expressions in hashes and arrays, and expands the results" do
60
70
  calculator.store(
61
71
  fruit_quantities: {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dentaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solomon White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-07 00:00:00.000000000 Z
11
+ date: 2020-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov