Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ruby CEL example #902

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jruby-9.4.8.0
jruby-9.4.7.0
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

source 'https://rubygems.org'

gem 'cel', '~> 0.2.3'
gem 'erb', '~> 4.0'
gem 'google-protobuf', '~> 4.27'
gem 'haml', '~> 5.2'
gem 'rspec-its'
gem 'rspec', '~> 3.13.0'
gem 'rspec-its'
gem 'slim', '~> 5.0'

gem 'rubocop', require: false
Expand Down
26 changes: 25 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
bigdecimal (3.1.8)
bigdecimal (3.1.8-java)
cel (0.2.3)
cgi (0.3.6)
cgi (0.3.6-java)
diff-lcs (1.5.1)
erb (4.0.4)
cgi (>= 0.3.3)
erb (4.0.4-java)
cgi (>= 0.3.3)
ffi (1.17.0-java)
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
google-protobuf (4.27.2-arm64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.27.2-java)
bigdecimal
ffi (~> 1)
ffi-compiler (~> 1)
rake (>= 13)
google-protobuf (4.27.2-x86_64-darwin)
bigdecimal
rake (>= 13)
google-protobuf (4.27.2-x86_64-linux)
bigdecimal
rake (>= 13)
haml (5.2.2)
temple (>= 0.8.0)
tilt
Expand All @@ -22,6 +43,7 @@ GEM
racc (1.8.0)
racc (1.8.0-java)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.3.1)
strscan
Expand Down Expand Up @@ -76,7 +98,9 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
cel (~> 0.2.3)
erb (~> 4.0)
google-protobuf (~> 4.27)
haml (~> 5.2)
rspec (~> 3.13.0)
rspec-its
Expand All @@ -85,4 +109,4 @@ DEPENDENCIES
slim (~> 5.0)

BUNDLED WITH
2.5.3
2.5.15
10 changes: 10 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ ruby.bundle_fetch(
name = "bundle",
gem_checksums = {
"ast-2.4.2": "1e280232e6a33754cde542bc5ef85520b74db2aac73ec14acef453784447cc12",
"bigdecimal-3.1.8": "a89467ed5a44f8ae01824af49cbc575871fa078332e8f77ea425725c1ffe27be",
"bigdecimal-3.1.8-java": "b9e94c14623fff8575f17a10320852219bbba92ecff4977571503d942687326e",
"cel-0.2.3": "eacd66662224b688fa9d4a169d9c8ed292edfb487b040dd6a2ab34f246abaa77",
"cgi-0.3.6": "c5e2c301437116b28fdfbb565452b9c1ee597901e68611367b4126b5d10feca3",
"cgi-0.3.6-java": "f94886a613c101f2f60c2e33ea8a42d6ad0b9a5fcda3d550e01f35b0271585af",
"diff-lcs-1.5.1": "273223dfb40685548436d32b4733aa67351769c7dea621da7d9dd4813e63ddfe",
"erb-4.0.4": "de116e106205c46bc01918789b611aaad1328dcc6e9f12cf8cd2cc60ef619717",
"erb-4.0.4-java": "3767088f230194a84316a5879f0c3dc5f2a96fb1c9a198c3e27d3f35d416c597",
"ffi-1.17.0-java": "f65f022616970fcde83fe176393eb873a7b959ef2703f94931cf0af6ab55ec7a",
"ffi-compiler-1.3.2": "a94f3d81d12caf5c5d4ecf13980a70d0aeaa72268f3b9cc13358bcc6509184a0",
"google-protobuf-4.27.2-arm64-darwin": "36cbd6620ef822f8a93870cc837212b302cbbdd7c900f8fa6701c735b7ff7f97",
"google-protobuf-4.27.2-java": "e70eda54bf6bcd659c4e685c91cb7f00b7f4b3675467eca085a8409c8f4dfe53",
"google-protobuf-4.27.2-x86_64-darwin": "689f921050489d3cc2537c48bee98047414ad099bb980538562955a3bc9fdced",
"google-protobuf-4.27.2-x86_64-linux": "126183186de79f709a0792f31eddf1fcebbfb5ded29538d184ece8fae73148c2",
"haml-5.2.2": "6e759246556145642ef832d670fc06f9bd8539159a0e600847a00291dd7aae0c",
"json-2.7.2": "1898b5cbc81cd36c0fd4d0b7ad2682c39fb07c5ff682fc6265f678f550d4982c",
"json-2.7.2-java": "138e3038b5361b3d06ee2e8aa2be00bed0d0de4ef5f1553fc5935e5b93aca7ee",
Expand All @@ -58,6 +67,7 @@ ruby.bundle_fetch(
"racc-1.8.0": "09349a65c37c4fe710a435f25c9f1652e39f29ad6b1fa08d4a8d30c0553d3a08",
"racc-1.8.0-java": "3688448632150682bbd708b199961129aed2266107e26fcacb45c997395c19f9",
"rainbow-3.1.1": "039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a",
"rake-13.2.1": "46cb38dae65d7d74b6020a4ac9d48afed8eb8149c040eccf0523bec91907059d",
"regexp_parser-2.9.2": "5a27e767ad634f8a4b544520d5cd28a0db7aa1198a5d7c9d7e11d7b3d9066446",
"rexml-3.3.1": "34af9fb38eff6c451abd187c53fded98378aa91766d4c62fbbce10e40ed7c325",
"rspec-3.13.0": "d490914ac1d5a5a64a0e1400c1d54ddd2a501324d703b8cfe83f458337bab993",
Expand Down
12 changes: 11 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/ruby/cel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@rules_ruby//ruby:defs.bzl", "rb_binary", "rb_test")

rb_binary(
name = "cel",
srcs = ["cel.rb"],
main = "cel.rb",
deps = [
"@bundle",
],
)
19 changes: 19 additions & 0 deletions src/ruby/cel/cel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "cel"

env = Cel::Environment.new(name: :string, group: :string)

begin
ast = env.compile('name.startsWith("/groups/" + group)') #=> Cel::Types[:bool], which is == :bool
rescue Cel::Error => e
STDERR.puts("type-check error: #{e.message}")
raise e
end

prg = env.program(ast)

return_value = prg.evaluate(
name: Cel::String.new("/groups/acme.co/documents/secret-stuff"),
group: Cel::String.new("acme.co"),
)

puts return_value #=> true
Loading