cel 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd670ce6076540d040019d05ad1ae2a67bd8a8d94f60e51ea860090f69d4f179
4
- data.tar.gz: 76782582c4d81ddb8dbd5fda83c67a56635a30eebe88cf9320bcfe21f7926c9c
3
+ metadata.gz: 288ce099928eb32ac8c45875c0d0219d9f61f29bb81c8a44f4bc52d8e821da69
4
+ data.tar.gz: 64d61f4d2934e7ff455cb47472a2b5d6dc87a2d6ad73380ed34401be5ae58a20
5
5
  SHA512:
6
- metadata.gz: 40cadbc9e54c3ae8ea219c6d1a41bae8242ced85f8474115a865a70eff65fb234935874bcaf1d6b467b615f92224c4a6dba31aee30af9628585e77bb809d6ecd
7
- data.tar.gz: 1f8269fb2391074acecedae34645d0cb3bd0c06eda26004d99f8fd7ea15b26735c2796f5124c74b474133aabe639a739599e248d280cd630f8c2e7d6dd94a6a6
6
+ metadata.gz: 180607d29b2dac71d3a73ff3f25fb406809918c354994089a9bfa02ea5a7c97ec68487b59d054a7aa576bf6268a5c486e35a41694a55e19e67f59e2595401021
7
+ data.tar.gz: 7d3555dedbf3021e1d81ece6f22581058378c8edfe716913f088f73a25aeb2baadb908a02f0aef428291377e9d97425dd25e64668312d80e928e86c3c362c90a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2022-08-11
4
+
5
+ * fixed handling of comparison of primmitive types with Cel types.
6
+ * fixed truffleruby compatibility by improving parser number handling.
7
+
3
8
  ## [0.1.0] - 2021-11-23
4
9
 
5
10
  - 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 and check
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
- # evaluate
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 GitHub at https://gitlab.com/honeyryderchuck/cel-ruby.
112
+ Bug reports and pull requests are welcome on Gitlab at https://gitlab.com/honeyryderchuck/cel-ruby.
@@ -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.map do |k, v|
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.to_h)
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.map do |k, v|
234
+ value = value.to_h do |k, v|
235
235
  [Literal.to_cel_type(k), Literal.to_cel_type(v)]
236
- end.to_h
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.map { |typ| [typ, Type.new(typ)] }.to_h
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.5.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/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cel
4
4
  module Ruby
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-23 00:00:00.000000000 Z
11
+ date: 2022-08-11 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
  - - ">="
@@ -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.2.14
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.