cel-rs-rb 0.2.0.pre.1-x86_64-linux

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0bb26cd6624af6234cbe2ede8df8bb8e113326905b40cc57892095aefc25704e
4
+ data.tar.gz: e062eac65700fcd3daa9b76da9d87cc473cc7350a69fb6668b9d94dd1f5f2440
5
+ SHA512:
6
+ metadata.gz: 4f6bf5242d1a5045fe923de822be8aa664cf8452f1595a956cd70cb712f8ef7418c8770b9a951b652795b579a35700131e0604f5351b1a692f3577e93c35d149
7
+ data.tar.gz: b6f8e19deaf7f886bb1a50d4201a500fb05165721f1c60e5fad5b6dc12239f2e3f5e61a569cb78b5ae428fb63c917c9060e3a45f16ed48da00ac03ba60fd555d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chris Atkins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # cel-rs-rb
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/cel-rs-rb.svg)](https://rubygems.org/gems/cel-rs-rb)
4
+
5
+ Ruby bindings for the Rust [`cel`](https://crates.io/crates/cel) crate, implemented with [Magnus](https://github.com/matsadler/magnus).
6
+
7
+ ## Goals
8
+
9
+ - Ruby-first API over the Rust CEL engine
10
+ - Close semantic compatibility with Rust `cel::Program` + `cel::Context`
11
+ - Ruby variable and function interop
12
+ - Thread-safe concurrent execution
13
+ - GVL released while CEL evaluation runs
14
+
15
+ ## Installation
16
+
17
+ ```ruby
18
+ gem "cel-rs-rb"
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "cel"
25
+
26
+ context = CEL::Context.build(user: {"name" => "Ada"}, scores: [10, 20, 30]) do |ctx|
27
+ ctx.define_function("sum") { |*args| args.sum }
28
+ end
29
+
30
+ program = CEL.compile("sum(scores[0], scores[1], scores[2])")
31
+ program.execute(context)
32
+ # => 60
33
+ ```
34
+
35
+ ### API mapping
36
+
37
+ - `CEL.compile(source)` -> `CEL::Program`
38
+ - `CEL::Program.compile(source)` -> `CEL::Program`
39
+ - `CEL::Program#execute(context = nil)` -> Ruby value
40
+ - `CEL::Program#references` -> `{ "variables" => [...], "functions" => [...] }`
41
+ - `CEL::Context.new(empty = false)` -> context with builtins (`false`) or empty (`true`)
42
+ - `CEL::Context#add_variable(name, value)`
43
+ - `CEL::Context#define_function(name) { |*args| ... }`
44
+ - `CEL::Duration.new(seconds)` -> duration value for context variables and duration results
45
+
46
+ ## Type support
47
+
48
+ ### Ruby -> CEL
49
+
50
+ - `nil` -> `null`
51
+ - `true/false` -> `bool`
52
+ - `Integer` -> `int`
53
+ - `Float` -> `double`
54
+ - `String` / `Symbol` -> `string`
55
+ - binary `String` (`ASCII-8BIT`, e.g. `"abc".b`) -> `bytes`
56
+ - `Time` -> `timestamp`
57
+ - `CEL::Duration` -> `duration`
58
+ - `Array` -> `list`
59
+ - `Hash` with keys `String|Symbol|Integer|Boolean` -> `map`
60
+
61
+ ### CEL -> Ruby
62
+
63
+ - `null` -> `nil`
64
+ - scalar primitives map naturally
65
+ - `bytes` -> binary Ruby `String`
66
+ - `timestamp` -> `Time`
67
+ - `duration` -> `CEL::Duration`
68
+ - `list` -> `Array`
69
+ - `map` -> `Hash`
70
+
71
+ ## Error classes
72
+
73
+ - `CEL::Error`
74
+ - `CEL::ParseError`
75
+ - `CEL::ExecutionError`
76
+ - `CEL::TypeError`
77
+
78
+ ## Thread safety and concurrency
79
+
80
+ - Compiled `CEL::Program` instances can be shared and executed concurrently from
81
+ multiple Ruby threads with separate execution contexts.
82
+ - Each thread may pass its own `CEL::Context`; context data is mutex-protected
83
+ and copied into an immutable execution snapshot for each run.
84
+ - CEL evaluation runs with the Ruby GVL released, so other Ruby threads can keep
85
+ progressing while a program executes.
86
+ - Ruby callbacks from CEL functions temporarily re-acquire the GVL before
87
+ invoking Ruby code.
88
+
89
+ ## Development
90
+
91
+ ### Tooling
92
+
93
+ Uses [mise](https://mise.jdx.dev/) for versions:
94
+
95
+ ```toml
96
+ [tools]
97
+ ruby = "4.0"
98
+ rust = "1.96.0"
99
+ ```
100
+
101
+ ### Test + lint
102
+
103
+ ```bash
104
+ bundle exec rake
105
+ ```
106
+
107
+ This runs:
108
+
109
+ - `standard` (format/lint)
110
+ - native extension compile
111
+ - `rspec`
112
+
113
+ CI also runs the test suite on Ruby 3.3, Ruby 3.4, and Ruby 4.0 through Buildkite.
114
+
115
+ ## Releasing
116
+
117
+ Releases publish **precompiled native gems** for five platforms
118
+ (`x86_64-linux`, `aarch64-linux`, `x86_64-linux-musl`, `arm64-darwin`,
119
+ `x86_64-darwin`) to [rubygems.org](https://rubygems.org/gems/cel-rs-rb).
120
+
121
+ ### Cutting a release
122
+
123
+ The gem version comes from `lib/cel/version.rb`, not from the tag, so bump the
124
+ file and tag the same version:
125
+
126
+ ```bash
127
+ # 1. Bump CEL::VERSION in lib/cel/version.rb (e.g. "0.2.0")
128
+ # 2. Commit the bump
129
+ git commit -am "Release v0.2.0"
130
+
131
+ # 3. Tag that commit (the v-prefix triggers the release pipeline)
132
+ git tag v0.2.0
133
+ git push origin main
134
+ git push origin v0.2.0
135
+ ```
136
+
137
+ The `release:verify-tag` step fails the build if the tag and
138
+ `CEL::VERSION` disagree, so the tag (`v0.2.0`) must match `version.rb`
139
+ (`0.2.0`).
140
+
141
+ ## Compatibility notes
142
+
143
+ - Some CEL value variants (e.g. opaque custom Rust types) cannot be fully marshaled to Ruby and raise `CEL::TypeError`.
144
+ - This project targets broad CEL compatibility, but parity for every Rust-only extension point is still evolving.
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CEL
4
+ VERSION = "0.2.0.pre.1"
5
+ end
data/lib/cel.rb ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cel/version"
4
+
5
+ begin
6
+ RUBY_VERSION =~ /(\d+\.\d+)/
7
+ require "cel/#{Regexp.last_match(1)}/cel"
8
+ rescue LoadError
9
+ require "cel/cel"
10
+ end
11
+
12
+ module CEL
13
+ class Context
14
+ class << self
15
+ alias_method :__native_new, :new
16
+
17
+ def new(empty = false)
18
+ __native_new(!!empty)
19
+ end
20
+
21
+ def build(empty: false, **variables)
22
+ ctx = new(empty)
23
+ variables.each { |k, v| ctx.add_variable(k.to_s, v) }
24
+ yield(ctx) if block_given?
25
+ ctx
26
+ end
27
+ end
28
+
29
+ def define_function(name, &block)
30
+ raise ArgumentError, "block required" unless block
31
+
32
+ add_function(name.to_s, block)
33
+ end
34
+ end
35
+
36
+ class Program
37
+ alias_method :__native_execute, :execute
38
+
39
+ def execute(context = nil)
40
+ return __native_execute if context.nil?
41
+
42
+ execute_with_context(context)
43
+ end
44
+
45
+ def call(context = nil)
46
+ execute(context)
47
+ end
48
+ end
49
+ end
data/spec/cel_spec.rb ADDED
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "time"
5
+
6
+ RSpec.describe CEL do
7
+ describe ".compile" do
8
+ it "compiles and executes simple expressions" do
9
+ program = CEL.compile("1 + 1")
10
+ expect(program.execute).to eq(2)
11
+ end
12
+
13
+ it "raises parse errors for invalid programs" do
14
+ expect { CEL.compile("1 +") }.to raise_error(CEL::ParseError)
15
+ end
16
+ end
17
+
18
+ describe CEL::Context do
19
+ it "supports ruby variables for basic types" do
20
+ context = CEL::Context.new
21
+ context.add_variable("nil_value", nil)
22
+ context.add_variable("flag", true)
23
+ context.add_variable("num", 41)
24
+ context.add_variable("float_num", 1.5)
25
+ context.add_variable("name", "cel")
26
+ context.add_variable("ary", [1, 2, 3])
27
+ context.add_variable("obj", {"a" => 1, :b => 2})
28
+
29
+ expect(CEL.compile("nil_value == null").execute(context)).to eq(true)
30
+ expect(CEL.compile("flag && true").execute(context)).to eq(true)
31
+ expect(CEL.compile("num + 1").execute(context)).to eq(42)
32
+ expect(CEL.compile("float_num + 0.5").execute(context)).to eq(2.0)
33
+ expect(CEL.compile("name.startsWith('c')").execute(context)).to eq(true)
34
+ expect(CEL.compile("ary[2]").execute(context)).to eq(3)
35
+ expect(CEL.compile("obj.a + obj.b").execute(context)).to eq(3)
36
+ end
37
+
38
+ it "supports ruby values for CEL bytes, timestamp, and duration types" do
39
+ context = CEL::Context.build(
40
+ bytes: "abc".b,
41
+ at: Time.utc(2023, 5, 29),
42
+ delay: CEL::Duration.new(90)
43
+ )
44
+
45
+ expect(CEL.compile("bytes == b'abc'").execute(context)).to eq(true)
46
+ expect(CEL.compile("at == timestamp('2023-05-29T00:00:00Z')").execute(context)).to eq(true)
47
+ expect(CEL.compile("delay == duration('90s')").execute(context)).to eq(true)
48
+ end
49
+
50
+ it "registers ruby functions and supports variadic calls" do
51
+ context = CEL::Context.new
52
+ context.define_function("sum") do |*values|
53
+ values.flatten.sum
54
+ end
55
+
56
+ expect(CEL.compile("sum(1, 2, 3)").execute(context)).to eq(6)
57
+ end
58
+
59
+ it "passes method receiver as first block arg for method calls" do
60
+ context = CEL::Context.new(true)
61
+ context.define_function("startsWith") { |target, prefix| target.start_with?(prefix) }
62
+
63
+ expect(CEL.compile("'hello'.startsWith('he')").execute(context)).to eq(true)
64
+ end
65
+
66
+ it "raises clear type error for unsupported variable types" do
67
+ context = CEL::Context.new
68
+ expect { context.add_variable("bad", Object.new) }.to raise_error(CEL::TypeError)
69
+ end
70
+ end
71
+
72
+ describe CEL::Program do
73
+ it "exposes references" do
74
+ program = CEL.compile("size(foo) > 0")
75
+ refs = program.references
76
+ expect(refs["variables"]).to include("foo")
77
+ expect(refs["functions"]).to include("size")
78
+ end
79
+
80
+ it "ports core CEL suite behavior examples" do
81
+ tests = {
82
+ "size([1,2,3]) == 3" => true,
83
+ "[1,2,3].map(x, x * 2)" => [2, 4, 6],
84
+ "[1,2,3].filter(x, x > 1)" => [2, 3],
85
+ "[1,2,3].exists(x, x == 2)" => true,
86
+ "[1,2,3].all(x, x > 0)" => true,
87
+ "{'a': 1}.contains('a')" => true,
88
+ "optional.of(1).hasValue()" => true
89
+ }
90
+
91
+ tests.each do |expr, expected|
92
+ expect(CEL.compile(expr).execute).to eq(expected)
93
+ end
94
+ end
95
+
96
+ it "marshals current CEL scalar value variants back to ruby" do
97
+ bytes = CEL.compile("b'abc'").execute
98
+ expect(bytes).to eq("abc".b)
99
+ expect(bytes.encoding).to eq(Encoding::ASCII_8BIT)
100
+
101
+ timestamp = CEL.compile("timestamp('2023-05-29T00:00:00Z')").execute
102
+ expect(timestamp).to be_a(Time)
103
+ expect(timestamp.getutc.iso8601).to eq("2023-05-29T00:00:00Z")
104
+
105
+ duration = CEL.compile("duration('1m30s')").execute
106
+ expect(duration).to be_a(CEL::Duration)
107
+ expect(duration.total_seconds).to eq(90.0)
108
+ expect(duration).to eq(CEL::Duration.new(90))
109
+ end
110
+
111
+ it "returns execution errors as CEL::ExecutionError" do
112
+ program = CEL.compile("1 / 0")
113
+ expect { program.execute }.to raise_error(CEL::ExecutionError)
114
+ end
115
+
116
+ it "releases GVL so other ruby threads can progress" do
117
+ context = CEL::Context.new
118
+ context.add_variable("items", Array.new(15_000, 1))
119
+ program = CEL.compile("items.map(x, x + 1)")
120
+
121
+ marker = Queue.new
122
+ worker = Thread.new do
123
+ 100.times do
124
+ marker << :tick
125
+ sleep(0.001)
126
+ end
127
+ end
128
+
129
+ runner = Thread.new { program.execute(context) }
130
+
131
+ sleep(0.01)
132
+ expect(marker.size).to be > 0
133
+
134
+ runner.join
135
+ worker.join
136
+ end
137
+
138
+ it "executes the same program concurrently with independent contexts" do
139
+ program = CEL.compile("items.map(x, x + offset).filter(x, x > cutoff).size() + id")
140
+ ready = Queue.new
141
+ start = Queue.new
142
+
143
+ threads = Array.new(8) do |id|
144
+ Thread.new do
145
+ ready << true
146
+ start.pop
147
+
148
+ offset = id % 3
149
+ context = CEL::Context.build(
150
+ id: id,
151
+ items: Array.new(200, id),
152
+ offset: offset,
153
+ cutoff: id
154
+ )
155
+
156
+ 25.times.map { program.execute(context) }
157
+ end
158
+ end
159
+ 8.times { ready.pop }
160
+ 8.times { start << true }
161
+ results = threads.map(&:value)
162
+
163
+ expected = Array.new(8) do |id|
164
+ offset = id % 3
165
+ value = (offset.zero? ? 0 : 200) + id
166
+ Array.new(25, value)
167
+ end
168
+
169
+ expect(results).to eq(expected)
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ end
8
+
9
+ require "cel"
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cel-rs-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.pre.1
5
+ platform: x86_64-linux
6
+ authors:
7
+ - CEL Ruby Contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.4'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.22'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.22'
69
+ - !ruby/object:Gem::Dependency
70
+ name: standard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.55'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.55'
83
+ description: Robust Ruby bindings to the Rust CEL implementation using Magnus
84
+ email: []
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - LICENSE
90
+ - README.md
91
+ - lib/cel.rb
92
+ - lib/cel/3.3/cel.so
93
+ - lib/cel/3.4/cel.so
94
+ - lib/cel/4.0/cel.so
95
+ - lib/cel/version.rb
96
+ - spec/cel_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: https://github.com/buildkite/cel-rs-rb
99
+ licenses:
100
+ - MIT
101
+ metadata:
102
+ homepage_uri: https://github.com/buildkite/cel-rs-rb
103
+ source_code_uri: https://github.com/buildkite/cel-rs-rb
104
+ rubygems_mfa_required: 'true'
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '3.3'
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: 4.1.dev
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.5.23
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Ruby bindings for the Rust CEL crate
127
+ test_files: []