dmn 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dmn/nodes.rb +13 -15
- data/lib/dmn/parser.rb +4 -4
- data/lib/dmn/rule.rb +1 -1
- data/lib/dmn/unary_tests.rb +2 -2
- data/lib/dmn/version.rb +1 -1
- data/lib/dmn.rb +0 -5
- metadata +12 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83ab9c509d78447fc0dcf11d993e79c9105baf97904af53e932e16ae7eaee2df
|
4
|
+
data.tar.gz: be469b68cdeab12f0ffee64e6a1c884ee9b67d10e2d9b899f1f3ecfa7905a975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5b1b6a24a4c6d2f305d41e94ac83bcb951f1dbfe8fc4ddccc6d5675ee5f3af70529778f288db5c7dea989a5ef7af685250ad6b7abd5dea7b80bef1afe20d019
|
7
|
+
data.tar.gz: 62e2cecb612379245854e09684e1632ae6fb670d0618577685d00e92c944aaf44c9e8a5e59173372280a5887879a190603bd1ec47e07f34bebb9e533f91d9a3b
|
data/lib/dmn/nodes.rb
CHANGED
@@ -6,7 +6,7 @@ module DMN
|
|
6
6
|
# Takes a context hash and returns an array of qualified names
|
7
7
|
# { "person": { "name": { "first": "Eric", "last": "Carlson" }, "age": 60 } } => ["person", "person.name.first", "person.name.last", "person.age"]
|
8
8
|
#
|
9
|
-
def qualified_names_in_context(hash = {}, prefix =
|
9
|
+
def qualified_names_in_context(hash = {}, prefix = "", qualified_names = Set.new)
|
10
10
|
hash.each do |key, value|
|
11
11
|
new_prefix = prefix.empty? ? "#{key}" : "#{prefix}.#{key}"
|
12
12
|
if value.is_a?(Hash)
|
@@ -114,13 +114,13 @@ module DMN
|
|
114
114
|
second_val = second.eval(context)
|
115
115
|
|
116
116
|
case [start, finish]
|
117
|
-
when [
|
117
|
+
when ["(", ")"]
|
118
118
|
->(input) { first_val < input && input < second_val }
|
119
|
-
when [
|
119
|
+
when ["[", "]"]
|
120
120
|
->(input) { first_val <= input && input <= second_val }
|
121
|
-
when [
|
121
|
+
when ["(", "]"]
|
122
122
|
->(input) { first_val < input && input <= second_val }
|
123
|
-
when [
|
123
|
+
when ["[", ")"]
|
124
124
|
->(input) { first_val <= input && input < second_val }
|
125
125
|
end
|
126
126
|
end
|
@@ -228,7 +228,7 @@ module DMN
|
|
228
228
|
raise_evaluation_error(head.text_value, context) if DMN.config.strict && !context.key?(head.text_value.to_sym)
|
229
229
|
context[head.text_value.to_sym]
|
230
230
|
else
|
231
|
-
tail.elements.flat_map { |element| element.name.text_value.split(
|
231
|
+
tail.elements.flat_map { |element| element.name.text_value.split(".") }.inject(context[head.text_value.to_sym]) do |hash, key|
|
232
232
|
raise_evaluation_error("#{head.text_value}#{tail.text_value}", context) if DMN.config.strict && (hash.blank? || !hash.key?(key.to_sym))
|
233
233
|
return nil unless hash
|
234
234
|
hash[key.to_sym]
|
@@ -492,12 +492,12 @@ module DMN
|
|
492
492
|
class Comparison < Node
|
493
493
|
def eval(context = {})
|
494
494
|
case operator.text_value
|
495
|
-
when
|
496
|
-
when
|
497
|
-
when
|
498
|
-
when
|
499
|
-
when
|
500
|
-
when
|
495
|
+
when "<" then left.eval(context) < right.eval(context)
|
496
|
+
when "<=" then left.eval(context) <= right.eval(context)
|
497
|
+
when ">=" then left.eval(context) >= right.eval(context)
|
498
|
+
when ">" then left.eval(context) > right.eval(context)
|
499
|
+
when "!=" then left.eval(context) != right.eval(context)
|
500
|
+
when "=" then left.eval(context) == right.eval(context)
|
501
501
|
end
|
502
502
|
end
|
503
503
|
end
|
@@ -522,7 +522,7 @@ module DMN
|
|
522
522
|
# 53. instance of = expression , "instance" , "of" , type ;
|
523
523
|
#
|
524
524
|
class InstanceOf < Node
|
525
|
-
def eval(
|
525
|
+
def eval(_context = {})
|
526
526
|
case type.text_value
|
527
527
|
when "string"
|
528
528
|
->(input) { input.is_a?(String) }
|
@@ -556,8 +556,6 @@ module DMN
|
|
556
556
|
->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:seconds] }
|
557
557
|
when "time duration"
|
558
558
|
->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:hours, :minutes, :seconds] }
|
559
|
-
when "years and months duration"
|
560
|
-
->(input) { input.is_a?(ActiveSupport::Duration) && input.parts.keys.sort == [:months, :years] }
|
561
559
|
when "list"
|
562
560
|
->(input) { input.is_a?(Array) }
|
563
561
|
when "interval"
|
data/lib/dmn/parser.rb
CHANGED
@@ -5,7 +5,7 @@ module DMN
|
|
5
5
|
# Load the Treetop grammar from the 'feel' file, and create a new
|
6
6
|
# instance of that parser as a class variable so we don't have to re-create
|
7
7
|
# it every time we need to parse a string
|
8
|
-
Treetop.load(File.expand_path(File.join(File.dirname(__FILE__),
|
8
|
+
Treetop.load(File.expand_path(File.join(File.dirname(__FILE__), "dmn.treetop")))
|
9
9
|
@@parser = DMNParser.new
|
10
10
|
|
11
11
|
def self.parse(expression, root: nil)
|
@@ -15,15 +15,15 @@ module DMN
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.parse_test(expression)
|
18
|
-
@@parser.parse(expression ||
|
18
|
+
@@parser.parse(expression || "-", root: :simple_unary_tests).tap do |ast|
|
19
19
|
raise SyntaxError, "Invalid unary test: #{expression.inspect}" unless ast
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.clean_tree(root_node)
|
24
24
|
return if(root_node.elements.nil?)
|
25
|
-
root_node.elements.delete_if{|node| node.class.name == "Treetop::Runtime::SyntaxNode" }
|
26
|
-
root_node.elements.each {|node| self.clean_tree(node) }
|
25
|
+
root_node.elements.delete_if{ |node| node.class.name == "Treetop::Runtime::SyntaxNode" }
|
26
|
+
root_node.elements.each { |node| self.clean_tree(node) }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/dmn/rule.rb
CHANGED
data/lib/dmn/unary_tests.rb
CHANGED
@@ -13,12 +13,12 @@ module DMN
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def valid?
|
16
|
-
return true if text.nil? || text ==
|
16
|
+
return true if text.nil? || text == "-"
|
17
17
|
tree.present?
|
18
18
|
end
|
19
19
|
|
20
20
|
def test(input, variables = {})
|
21
|
-
return true if text.nil? || text ==
|
21
|
+
return true if text.nil? || text == "-"
|
22
22
|
tree.eval(functions.merge(variables)).call(input)
|
23
23
|
end
|
24
24
|
end
|
data/lib/dmn/version.rb
CHANGED
data/lib/dmn.rb
CHANGED
@@ -2,14 +2,9 @@
|
|
2
2
|
|
3
3
|
require_relative "dmn/version"
|
4
4
|
|
5
|
-
require "awesome_print"
|
6
|
-
|
7
5
|
require "active_support"
|
8
|
-
require "active_support/duration"
|
9
6
|
require "active_support/time"
|
10
7
|
require "active_support/core_ext/hash"
|
11
|
-
require "active_support/core_ext/object/json"
|
12
|
-
require "active_support/configurable"
|
13
8
|
|
14
9
|
require "treetop"
|
15
10
|
require "xmlhasher"
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dmn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connected Bits
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-03 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activemodel
|
@@ -39,33 +38,33 @@ dependencies:
|
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: 7.0.2.3
|
41
40
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
41
|
+
name: ostruct
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
|
-
- - "
|
44
|
+
- - ">="
|
46
45
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
46
|
+
version: '0'
|
48
47
|
type: :runtime
|
49
48
|
prerelease: false
|
50
49
|
version_requirements: !ruby/object:Gem::Requirement
|
51
50
|
requirements:
|
52
|
-
- - "
|
51
|
+
- - ">="
|
53
52
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
53
|
+
version: '0'
|
55
54
|
- !ruby/object:Gem::Dependency
|
56
55
|
name: treetop
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
|
-
- -
|
58
|
+
- - '='
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
60
|
+
version: 1.6.12
|
62
61
|
type: :runtime
|
63
62
|
prerelease: false
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
65
64
|
requirements:
|
66
|
-
- -
|
65
|
+
- - '='
|
67
66
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
67
|
+
version: 1.6.12
|
69
68
|
- !ruby/object:Gem::Dependency
|
70
69
|
name: xmlhasher
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -293,7 +292,6 @@ licenses:
|
|
293
292
|
metadata:
|
294
293
|
homepage_uri: https://www.connectedbits.com
|
295
294
|
source_code_uri: https://github.com/connectedbits/bpmn/feel
|
296
|
-
post_install_message:
|
297
295
|
rdoc_options: []
|
298
296
|
require_paths:
|
299
297
|
- lib
|
@@ -308,8 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
308
306
|
- !ruby/object:Gem::Version
|
309
307
|
version: '0'
|
310
308
|
requirements: []
|
311
|
-
rubygems_version: 3.
|
312
|
-
signing_key:
|
309
|
+
rubygems_version: 3.6.5
|
313
310
|
specification_version: 4
|
314
311
|
summary: A light-weight DMN FEEL expression evaluator and business rule engine in
|
315
312
|
Ruby.
|