Module: Cel

Includes:
CollectionTypeFetch
Defined in:
lib/cel.rb,
lib/cel/macro.rb,
lib/cel/errors.rb,
lib/cel/parser.rb,
lib/cel/checker.rb,
lib/cel/context.rb,
lib/cel/encoder.rb,
lib/cel/program.rb,
lib/cel/version.rb,
lib/cel/ast/types.rb,
lib/cel/extensions.rb,
lib/cel/environment.rb,
lib/cel/ast/elements.rb,
lib/cel/ast/cel_methods.rb,
lib/cel/extensions/bind.rb,
lib/cel/extensions/math.rb,
lib/cel/ast/elements/map.rb,
lib/cel/ast/elements/bool.rb,
lib/cel/ast/elements/list.rb,
lib/cel/ast/elements/null.rb,
lib/cel/extensions/string.rb,
lib/cel/ast/elements/bytes.rb,
lib/cel/ast/elements/group.rb,
lib/cel/ast/elements/invoke.rb,
lib/cel/ast/elements/number.rb,
lib/cel/ast/elements/string.rb,
lib/cel/extensions/encoders.rb,
lib/cel/ast/elements/literal.rb,
lib/cel/ast/elements/message.rb,
lib/cel/ast/elements/duration.rb,
lib/cel/ast/elements/function.rb,
lib/cel/ast/elements/protobuf.rb,
lib/cel/ast/elements/condition.rb,
lib/cel/ast/elements/operation.rb,
lib/cel/ast/elements/timestamp.rb,
lib/cel/ast/elements/identifier.rb

Defined Under Namespace

Modules: CelMethods, CollectionTypeFetch, Encoder, Extensions, Macro, Protobuf, Ruby Classes: AbstractType, BindingError, Bool, Bytes, CheckError, Checker, Condition, Context, Duration, Environment, Error, EvaluateError, Function, Group, Identifier, InvalidArgumentError, Invoke, List, ListType, Literal, Map, MapType, MaxNestingDepthExceededError, MaxRecursionDepthExceededError, Message, NoCelMethodError, NoMatchingOverloadError, NoOverloadError, NoSuchFieldError, NoSuchKeyError, Null, Number, Operation, ParseError, Parser, Program, Runner, String, Timestamp, Type

Constant Summary collapse

MAX_INT =
(2**63)
MAX_FLOAT =
(2**63)
PRIMITIVE_TYPES =

Primitive Cel Types

%i[int uint double bool string bytes list map timestamp duration null_type type].freeze
COLTYPES =
%i[list map].freeze
TYPES =
(PRIMITIVE_TYPES - COLTYPES).to_h { |typ| [typ, Type.new(typ)] }
EXTENSIONS =
{
  math: Extensions::Math,
  strings: Extensions::String,
  base64: Extensions::Encoders::Base64,
  cel: Extensions::Bind,
}.freeze
LOGICAL_OPERATORS =
%w[<= >= < > == != in].freeze
MULTI_OPERATORS =
%w[* / %].freeze

Class Method Summary collapse

Methods included from CollectionTypeFetch

#[]

Class Method Details

.freezeObject



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/cel.rb', line 258

def freeze
  # freeze constants to make cel ractor-friendly
  Number.freeze
  Bool.freeze
  Null.freeze
  String.freeze
  Bytes.freeze
  List.freeze
  Map.freeze
  Timestamp.freeze
  Duration.freeze
  Type.freeze
  TYPES.each_value(&:freeze).freeze
  super
end

.package_to_module_name(type) ⇒ Object



247
248
249
250
251
252
253
254
255
256
# File 'lib/cel.rb', line 247

def package_to_module_name(type)
  namespace, type_msg = type.split("/", 2)
  type_msg ||= namespace # sometimes there's no namespace

  return unless /[[:upper:]]/.match?(type_msg)

  type_msg.split(".").map do |typ|
    /[[:upper:]]/.match?(typ[0]) ? typ : typ.capitalize
  end.join("::")
end

.to_numeric(anything) ⇒ Object



238
239
240
241
242
243
244
245
# File 'lib/cel.rb', line 238

def to_numeric(anything)
  num = BigDecimal(anything.to_s)
  if num.frac.zero?
    num.to_i
  else
    num.to_f
  end
end