cel 0.1.0 → 0.1.2
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/CHANGELOG.md +9 -0
- data/README.md +15 -4
- data/lib/cel/ast/elements.rb +5 -5
- data/lib/cel/ast/types.rb +1 -1
- data/lib/cel/parser.rb +6 -6
- data/lib/cel/program.rb +2 -2
- data/lib/cel/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d81d1083943f4f6d5bc415963b01c2f9be140074ae63493601b1613422fe29dd
|
4
|
+
data.tar.gz: 4ea24204656323c4bc8313293e64186973f28f84c4878b94804c5cb32b0cc047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d25e42ca7b497e2dccbaf239a649a1a66af83001d9580faabf511cc71d8db76eca1d9ededd0fbfb3ba9bde25834750809022983364b6591bf8da1c99c6673c
|
7
|
+
data.tar.gz: 4526e92a70b428e512654fccc94adbe9dd4a0a32534aa1792b5633a72e55cc95e67c4ef99b5ab5b272cf822e7a7175ef28e73ada9f2e61ca5613699d715a78ca
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.2] - 2022-11-10
|
4
|
+
|
5
|
+
point release to update links in rubygems.
|
6
|
+
|
7
|
+
## [0.1.1] - 2022-08-11
|
8
|
+
|
9
|
+
* fixed handling of comparison of primmitive types with Cel types.
|
10
|
+
* fixed truffleruby compatibility by improving parser number handling.
|
11
|
+
|
3
12
|
## [0.1.0] - 2021-11-23
|
4
13
|
|
5
14
|
- Initial release
|
data/README.md
CHANGED
@@ -34,15 +34,26 @@ require "cel"
|
|
34
34
|
# set the environment
|
35
35
|
env = Cel::Environment.new(name: :string, group: :string)
|
36
36
|
|
37
|
-
# parse
|
37
|
+
# 1.1 parse
|
38
38
|
begin
|
39
39
|
ast = env.compile('name.startsWith("/groups/" + group)') #=> Cel::Types[:bool], which is == :bool
|
40
40
|
rescue Cel::Error => e
|
41
41
|
STDERR.puts("type-check error: #{e.message}")
|
42
42
|
raise e
|
43
43
|
end
|
44
|
-
|
45
|
-
|
44
|
+
# 1.2 check
|
45
|
+
prg = env.program(ast)
|
46
|
+
# 1.3 evaluate
|
47
|
+
return_value = prg.evaluate(name: Cel::String.new("/groups/acme.co/documents/secret-stuff"),
|
48
|
+
group: Cel::String.new("acme.co")))
|
49
|
+
|
50
|
+
# 2.1 parse and check
|
51
|
+
prg = env.program('name.startsWith("/groups/" + group)')
|
52
|
+
# 2.2 then evaluate
|
53
|
+
return_value = prg.evaluate(name: Cel::String.new("/groups/acme.co/documents/secret-stuff"),
|
54
|
+
group: Cel::String.new("acme.co")))
|
55
|
+
|
56
|
+
# 3. or parse, check and evaluate
|
46
57
|
begin
|
47
58
|
return_value = env.evaluate(ast,
|
48
59
|
name: Cel::String.new("/groups/acme.co/documents/secret-stuff"),
|
@@ -98,4 +109,4 @@ Changes in the parser are therefore accomplished by modifying the `parser.ry` fi
|
|
98
109
|
|
99
110
|
## Contributing
|
100
111
|
|
101
|
-
Bug reports and pull requests are welcome on
|
112
|
+
Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/os85/cel-ruby.
|
data/lib/cel/ast/elements.rb
CHANGED
@@ -27,9 +27,9 @@ module Cel
|
|
27
27
|
|
28
28
|
def initialize(type, struct)
|
29
29
|
@struct = Struct.new(*struct.keys.map(&:to_sym)).new(*struct.values)
|
30
|
-
@type = type.is_a?(Type) ? type : MapType.new(struct.
|
30
|
+
@type = type.is_a?(Type) ? type : MapType.new(struct.to_h do |k, v|
|
31
31
|
[Literal.to_cel_type(k), Literal.to_cel_type(v)]
|
32
|
-
end
|
32
|
+
end)
|
33
33
|
super(@struct)
|
34
34
|
end
|
35
35
|
|
@@ -176,7 +176,7 @@ module Cel
|
|
176
176
|
LOGICAL_OPERATORS.each do |op|
|
177
177
|
class_eval(<<-OUT, __FILE__, __LINE__ + 1)
|
178
178
|
def #{op}(other)
|
179
|
-
Bool.new(super)
|
179
|
+
other.is_a?(Cel::Literal) ? Bool.new(super) : super
|
180
180
|
end
|
181
181
|
OUT
|
182
182
|
end
|
@@ -231,9 +231,9 @@ module Cel
|
|
231
231
|
|
232
232
|
class Map < Literal
|
233
233
|
def initialize(value)
|
234
|
-
value = value.
|
234
|
+
value = value.to_h do |k, v|
|
235
235
|
[Literal.to_cel_type(k), Literal.to_cel_type(v)]
|
236
|
-
end
|
236
|
+
end
|
237
237
|
super(MapType.new(value), value)
|
238
238
|
check
|
239
239
|
end
|
data/lib/cel/ast/types.rb
CHANGED
@@ -72,7 +72,7 @@ module Cel
|
|
72
72
|
# Primitive Cel Types
|
73
73
|
|
74
74
|
PRIMITIVE_TYPES = %i[int uint double bool string bytes list map null_type type].freeze
|
75
|
-
TYPES = PRIMITIVE_TYPES.
|
75
|
+
TYPES = PRIMITIVE_TYPES.to_h { |typ| [typ, Type.new(typ)] }
|
76
76
|
TYPES[:type] = Type.new(:type)
|
77
77
|
TYPES[:any] = Type.new(:any)
|
78
78
|
end
|
data/lib/cel/parser.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# DO NOT MODIFY!!!!
|
3
|
-
# This file is automatically generated by Racc 1.
|
3
|
+
# This file is automatically generated by Racc 1.6.0
|
4
4
|
# from Racc grammar file "".
|
5
5
|
#
|
6
6
|
|
@@ -142,21 +142,21 @@ def convert_to_number(scanner)
|
|
142
142
|
matched = scanner.matched
|
143
143
|
hexa, uint, number, floating, exp = scanner.captures
|
144
144
|
|
145
|
-
if !hexa.empty?
|
145
|
+
if hexa && !hexa.empty?
|
146
146
|
return [:tINT, hexa.to_i(16)]
|
147
147
|
end
|
148
148
|
|
149
|
-
if !uint.empty?
|
149
|
+
if uint && !uint.empty?
|
150
150
|
return [:tUINT, Integer(uint)]
|
151
151
|
end
|
152
152
|
|
153
|
-
if !exp.empty?
|
153
|
+
if exp && !exp.empty?
|
154
154
|
# third matched group, can only be a floating exponential, let's convert tout suite
|
155
155
|
[:tDOUBLE, BigDecimal(matched)]
|
156
|
-
elsif !floating.empty?
|
156
|
+
elsif floating && !floating.empty?
|
157
157
|
if number == floating || floating.start_with?(".")
|
158
158
|
[:tDOUBLE, Float(matched)]
|
159
|
-
elsif number.empty?
|
159
|
+
elsif number.nil? || number.empty?
|
160
160
|
[:tDOUBLE, BigDecimal(matched)]
|
161
161
|
end
|
162
162
|
else
|
data/lib/cel/program.rb
CHANGED
@@ -62,9 +62,9 @@ module Cel
|
|
62
62
|
# unary operations
|
63
63
|
values.first.__send__(:"#{op}@")
|
64
64
|
elsif op == "&&"
|
65
|
-
Bool.new(values.all? { |x|
|
65
|
+
Bool.new(values.all? { |x| true == x }) # rubocop:disable Style/YodaCondition
|
66
66
|
elsif op == "||"
|
67
|
-
Bool.new(values.any? { |x|
|
67
|
+
Bool.new(values.any? { |x| true == x }) # rubocop:disable Style/YodaCondition
|
68
68
|
elsif op == "in"
|
69
69
|
element, collection = values
|
70
70
|
Bool.new(collection.include?(element))
|
data/lib/cel/version.rb
CHANGED
metadata
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Cardoso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - ">="
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '0'
|
19
|
-
name: minitest
|
20
|
-
prerelease: false
|
21
20
|
type: :development
|
21
|
+
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
@@ -53,10 +53,10 @@ homepage:
|
|
53
53
|
licenses:
|
54
54
|
- Apache 2.0
|
55
55
|
metadata:
|
56
|
-
bug_tracker_uri: https://gitlab.com/
|
57
|
-
changelog_uri: https://gitlab.com/
|
58
|
-
source_code_uri: https://gitlab.com/
|
59
|
-
homepage_uri: https://gitlab.com/
|
56
|
+
bug_tracker_uri: https://gitlab.com/os85/cel-ruby/issues
|
57
|
+
changelog_uri: https://gitlab.com/os85/cel-ruby/-/blob/master/CHANGELOG.md
|
58
|
+
source_code_uri: https://gitlab.com/os85/cel-ruby
|
59
|
+
homepage_uri: https://gitlab.com/os85/cel-ruby
|
60
60
|
rubygems_mfa_required: 'true'
|
61
61
|
post_install_message:
|
62
62
|
rdoc_options: []
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.3.7
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: Pure Ruby implementation of Google Common Expression Language, https://opensource.google/projects/cel.
|