Class: Cel::Message
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Cel::Message
- Defined in:
- lib/cel/ast/elements.rb
Instance Attribute Summary collapse
-
#struct ⇒ Object
readonly
Returns the value of attribute struct.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #field?(key) ⇒ Boolean
-
#initialize(type, struct) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(type, struct) ⇒ Message
Returns a new instance of Message.
52 53 54 55 56 57 58 |
# File 'lib/cel/ast/elements.rb', line 52 def initialize(type, struct) @struct = Struct.new(*struct.keys.map(&:to_sym)).new(*struct.values) @type = type.is_a?(Type) ? type : MapType.new(struct.to_h do |k, v| [Literal.to_cel_type(k), Literal.to_cel_type(v)] end) super(@struct) end |
Instance Attribute Details
#struct ⇒ Object (readonly)
Returns the value of attribute struct.
43 44 45 |
# File 'lib/cel/ast/elements.rb', line 43 def struct @struct end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
43 44 45 |
# File 'lib/cel/ast/elements.rb', line 43 def type @type end |
Class Method Details
.convert_from_type(type, value) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cel/ast/elements.rb', line 64 def self.convert_from_type(type, value) case type when Invoke, Identifier spread_type = type.to_s Protobuf.convert_from_type(spread_type, value) when Type [type, value] else [ MapType.new(struct.to_h do |k, v| [Literal.to_cel_type(k), Literal.to_cel_type(v)] end), Struct.new(*struct.keys.map(&:to_sym)).new(*struct.values), ] end end |
.new(type, struct) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/cel/ast/elements.rb', line 45 def self.new(type, struct) value = convert_from_type(type, struct) return value if value.is_a?(Null) || value != struct super end |
Instance Method Details
#field?(key) ⇒ Boolean
60 61 62 |
# File 'lib/cel/ast/elements.rb', line 60 def field?(key) !@type.get(key).nil? end |