README.md in cel-0.2.0 vs README.md in cel-0.2.1

- old
+ new

@@ -1,10 +1,10 @@ # Cel::Ruby [![Gem Version](https://badge.fury.io/rb/cel.svg)](http://rubygems.org/gems/cel) -[![pipeline status](https://gitlab.com/honeyryderchuck/cel-ruby/badges/master/pipeline.svg)](https://gitlab.com/honeyryderchuck/cel-ruby/pipelines?page=1&scope=all&ref=master) -[![coverage report](https://gitlab.com/honeyryderchuck/cel-ruby/badges/master/coverage.svg?job=coverage)](https://honeyryderchuck.gitlab.io/cel-ruby/coverage/#_AllFiles) +[![pipeline status](https://gitlab.com/os85/cel-ruby/badges/master/pipeline.svg)](https://gitlab.com/os85/cel-ruby/pipelines?page=1&scope=all&ref=master) +[![coverage report](https://gitlab.com/os85/cel-ruby/badges/master/coverage.svg?job=coverage)](https://os85.gitlab.io/cel-ruby/coverage/#_AllFiles) Pure Ruby implementation of Google Common Expression Language, https://opensource.google/projects/cel. > The Common Expression Language (CEL) implements common semantics for expression evaluation, enabling different applications to more easily interoperate. @@ -43,28 +43,43 @@ end # 1.2 check prg = env.program(ast) # 1.3 evaluate return_value = prg.evaluate(name: Cel::String.new("/groups/acme.co/documents/secret-stuff"), - group: Cel::String.new("acme.co"))) + group: Cel::String.new("acme.co")) # 2.1 parse and check prg = env.program('name.startsWith("/groups/" + group)') # 2.2 then evaluate return_value = prg.evaluate(name: Cel::String.new("/groups/acme.co/documents/secret-stuff"), - group: Cel::String.new("acme.co"))) + group: Cel::String.new("acme.co")) # 3. or parse, check and evaluate begin return_value = env.evaluate(ast, name: Cel::String.new("/groups/acme.co/documents/secret-stuff"), - group: Cel::String.new("acme.co")) + group: Cel::String.new("acme.co") + ) rescue Cel::Error => e STDERR.puts("evaluation error: #{e.message}") raise e end puts return_value #=> true +``` + +### types + +`cel-ruby` supports declaring the types of variables in the environment, which allows for expression checking: + +```ruby +env = Cel::Environment.new( + first_name: :string, # shortcut for Cel::Types[:string] + middle_names: Cel::Types[:list, :string], # list of strings + last_name: :string +) + +# you can use Cel::Types to access any type of primitive type, i.e. Cel::Types[:bytes] ``` ### protobuf If `google/protobuf` is available in the environment, `cel-ruby` will also be able to integrate with protobuf declarations in CEL expressions.