diff --git a/bpmn/lib/bpmn/execution.rb b/bpmn/lib/bpmn/execution.rb index 61884ce..8428312 100644 --- a/bpmn/lib/bpmn/execution.rb +++ b/bpmn/lib/bpmn/execution.rb @@ -216,7 +216,7 @@ def evaluate_expression(expression, variables: parent&.variables || {}.with_indi return nil if expression.nil? if expression.start_with?("=") - DMN.evaluate(expression.delete_prefix("="), variables: variables) + FEEL.evaluate(expression.delete_prefix("="), variables: variables) else expression end @@ -393,10 +393,14 @@ def print_children end def print_child(child, index) - str = "#{index} #{child.step.class.name.demodulize} #{child.step.id}: #{child.status} #{JSON.pretty_generate(child.variables, { indent: '', object_nl: ' ' }) unless child.variables.empty? }".strip + vars = child.variables.empty? ? '' : JSON.pretty_generate(child.variables, { indent: '', object_nl: ' ' }) + name = child.step.name.present? ? " <#{child.step.name}>" : "" + + str = "#{index} #{child.step.class.name.demodulize} #{child.step.id}#{name}: #{child.status} #{vars}".strip str = "#{str} * in: #{child.tokens_in.join(', ')}" if child.tokens_in.present? str = "#{str} * out: #{child.tokens_out.join(', ')}" if child.tokens_out.present? puts str + child.children.each_with_index do |grandchild, grandindex| print_child(grandchild, "#{index}.#{grandindex}") end diff --git a/dmn/README.md b/dmn/README.md index e756b29..8a3f97c 100644 --- a/dmn/README.md +++ b/dmn/README.md @@ -2,7 +2,7 @@ A light-weight DMN (Decision Model and Notation) business rule ruby gem. -This gem depends on the [FEEL](https://github.com/connectedbits/bpmn/tree/main/feel) gem to evaluate DMN decision tables and expressions. +This gem depends on the [FEEL](https://github.com/connectedbits/workflow-kit/tree/main/feel) gem to evaluate DMN decision tables and expressions. ## Usage diff --git a/dmn/lib/dmn.rb b/dmn/lib/dmn.rb index 78acb45..3a2e00c 100644 --- a/dmn/lib/dmn.rb +++ b/dmn/lib/dmn.rb @@ -27,18 +27,6 @@ module DMN class SyntaxError < StandardError; end class EvaluationError < StandardError; end - def self.evaluate(expression_text, variables: {}) - literal_expression = FEEL::LiteralExpression.new(text: expression_text) - raise SyntaxError, "Expression is not valid" unless literal_expression.valid? - literal_expression.evaluate(variables) - end - - def self.test(input, unary_tests_text, variables: {}) - unary_tests = FEEL::UnaryTests.new(text: unary_tests_text) - raise SyntaxError, "Unary tests are not valid" unless unary_tests.valid? - unary_tests.test(input, variables) - end - def self.decide(decision_id, definitions: nil, definitions_json: nil, definitions_xml: nil, variables: {}) if definitions_xml.present? definitions = DMN::Definitions.from_xml(definitions_xml) diff --git a/feel/README.md b/feel/README.md index 3814cf6..98e0216 100644 --- a/feel/README.md +++ b/feel/README.md @@ -59,7 +59,7 @@ Calling a user-defined function: FEEL.config.functions = { "reverse": ->(s) { s.reverse } } -DMN.evaluate('reverse("Hello World!")', functions:) +FEEL.evaluate('reverse("Hello World!")') # => "!dlroW olleH" ``` @@ -138,6 +138,10 @@ UnaryTests.new(text: '> speed - speed_limit').variable_names - [x] Context: `get entries`, `get value`, `get keys` - [x] Temporal: `now`, `today`, `day of week`, `day of year`, `month of year`, `week of year` +### Comments +- [ ] Single-line +- [ ] Multi-line + ## Installation Execute: diff --git a/feel/lib/feel.rb b/feel/lib/feel.rb index 2530b05..fa70b04 100644 --- a/feel/lib/feel.rb +++ b/feel/lib/feel.rb @@ -26,13 +26,13 @@ class EvaluationError < StandardError; end def self.evaluate(expression_text, variables: {}) literal_expression = FEEL::LiteralExpression.new(text: expression_text) - raise SyntaxError, "Expression is not valid" unless literal_expression.valid? + raise SyntaxError, "Expression is not valid: #{expression_text}" unless literal_expression.valid? literal_expression.evaluate(variables) end def self.test(input, unary_tests_text, variables: {}) unary_tests = FEEL::UnaryTests.new(text: unary_tests_text) - raise SyntaxError, "Unary tests are not valid" unless unary_tests.valid? + raise SyntaxError, "Unary tests are not valid: #{unary_tests_text}" unless unary_tests.valid? unary_tests.test(input, variables) end