Class: Cel::Invoke

Inherits:
Object
  • Object
show all
Defined in:
lib/cel/ast/elements/invoke.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(func:, var: nil, args: nil, depth: 1, package: nil) ⇒ Invoke

Returns a new instance of Invoke.



17
18
19
20
21
22
23
# File 'lib/cel/ast/elements/invoke.rb', line 17

def initialize(func:, var: nil, args: nil, depth: 1, package: nil)
  @var = var
  @func = func.to_sym
  @args = args
  @package = package
  @depth = depth
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



7
8
9
# File 'lib/cel/ast/elements/invoke.rb', line 7

def args
  @args
end

#depthObject (readonly)

Returns the value of attribute depth.



7
8
9
# File 'lib/cel/ast/elements/invoke.rb', line 7

def depth
  @depth
end

#funcObject (readonly)

Returns the value of attribute func.



7
8
9
# File 'lib/cel/ast/elements/invoke.rb', line 7

def func
  @func
end

#varObject

Returns the value of attribute var.



5
6
7
# File 'lib/cel/ast/elements/invoke.rb', line 5

def var
  @var
end

Class Method Details

.new(func:, var: nil, args: nil, **rest) ⇒ Object



9
10
11
# File 'lib/cel/ast/elements/invoke.rb', line 9

def self.new(func:, var: nil, args: nil, **rest)
  Protobuf.try_invoke_from(var, func, args) || super
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/cel/ast/elements/invoke.rb', line 25

def ==(other)
  case other
  when Invoke
    @var == other.var && @func == other.func && @args == other.args
  when Array
    [@var, @func, @args].compact == other
  else
    super
  end
end

#indexing?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/cel/ast/elements/invoke.rb', line 60

def indexing?
  @func == :[]
end

#to_sObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cel/ast/elements/invoke.rb', line 36

def to_s
  if var
    if indexing?
      "#{var}[#{args}]"
    else
      "#{var}.#{func}#{"(#{args.map(&:to_s).join(", ")})" if args}"
    end
  else
    "#{func}#{"(#{args.map(&:to_s).join(", ")})" if args}"
  end
end

#try_convert_to_proto_typeObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cel/ast/elements/invoke.rb', line 48

def try_convert_to_proto_type
  return unless @var

  proto_type = Protobuf.convert_to_proto_type(@var.to_s, @package)

  return unless proto_type

  return proto_type unless proto_type.const_defined?(@func)

  proto_type.const_get(@func)
end

#typeObject



13
14
15
# File 'lib/cel/ast/elements/invoke.rb', line 13

def type
  TYPES[:any]
end