Class: Cel::Message

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

Constant Summary collapse

EMPTY_STRUCT =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, struct, package: nil, depth: 1) ⇒ Message

Returns a new instance of Message.



9
10
11
12
13
14
# File 'lib/cel/ast/elements/message.rb', line 9

def initialize(name, struct, package: nil, depth: 1)
  @struct = struct ? struct.transform_keys(&:to_sym) : EMPTY_STRUCT
  @name = name
  @package = package
  @depth = depth
end

Instance Attribute Details

#depthObject (readonly)

Returns the value of attribute depth.



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

def depth
  @depth
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#packageObject (readonly)

Returns the value of attribute package.



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

def package
  @package
end

#structObject (readonly)

Returns the value of attribute struct.



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

def struct
  @struct
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
# File 'lib/cel/ast/elements/message.rb', line 32

def ==(other)
  other.is_a?(Cel::Message) && other.name == @name && other.struct == @struct
end

#message_typeObject



24
25
26
# File 'lib/cel/ast/elements/message.rb', line 24

def message_type
  @message_type ||= proto_type || container
end

#proto_typeObject



28
29
30
# File 'lib/cel/ast/elements/message.rb', line 28

def proto_type
  @proto_type ||= Protobuf.convert_to_proto_type(@name.to_s, @package)
end

#to_sObject



36
37
38
39
40
41
42
# File 'lib/cel/ast/elements/message.rb', line 36

def to_s
  if proto_type
    proto_type.descriptor.name
  else
    message_type.to_s
  end
end

#typeObject



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

def type
  @type ||= if proto_type
    Protobuf.convert_to_cel_type(proto_type, @package) || proto_type
  else
    Protobuf.try_convert_from_wrapper_type(@name.to_s)
  end
end