Class: Protod::Interpreter::Base
- Inherits:
-
Object
- Object
- Protod::Interpreter::Base
- Defined in:
- lib/protod/interpreter.rb
Instance Attribute Summary collapse
-
#const ⇒ Object
readonly
Returns the value of attribute const.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #bindable? ⇒ Boolean
- #bound? ⇒ Boolean
-
#initialize(const, parent: nil, path: nil) ⇒ Base
constructor
A new instance of Base.
- #package ⇒ Object
- #pb_const ⇒ Object
- #proto_full_ident ⇒ Object
- #proto_ident ⇒ Object
- #proto_message ⇒ Object
- #proto_path ⇒ Object
- #set_parent(v) ⇒ Object
- #to_pb_from(rb) ⇒ Object
- #to_rb_from(pb) ⇒ Object
Constructor Details
#initialize(const, parent: nil, path: nil) ⇒ Base
Returns a new instance of Base.
117 118 119 120 121 |
# File 'lib/protod/interpreter.rb', line 117 def initialize(const, parent: nil, path: nil) @const = const @parent = parent @path = path end |
Instance Attribute Details
#const ⇒ Object (readonly)
Returns the value of attribute const.
115 116 117 |
# File 'lib/protod/interpreter.rb', line 115 def const @const end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
115 116 117 |
# File 'lib/protod/interpreter.rb', line 115 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
115 116 117 |
# File 'lib/protod/interpreter.rb', line 115 def path @path end |
Instance Method Details
#==(other) ⇒ Object
123 124 125 |
# File 'lib/protod/interpreter.rb', line 123 def ==(other) const == other.const && parent == other.parent && path == other.path end |
#bindable? ⇒ Boolean
127 128 129 130 131 |
# File 'lib/protod/interpreter.rb', line 127 def bindable? return false unless return false if bound? true end |
#bound? ⇒ Boolean
133 134 135 136 137 |
# File 'lib/protod/interpreter.rb', line 133 def bound? return false unless parent.nil?.! end |
#package ⇒ Object
144 145 146 147 148 |
# File 'lib/protod/interpreter.rb', line 144 def package return parent if parent.is_a?(Protod::Proto::Package) parent&.ancestor_as(Protod::Proto::Package) end |
#pb_const ⇒ Object
166 167 168 169 |
# File 'lib/protod/interpreter.rb', line 166 def pb_const &.pb_const || Google::Protobuf::DescriptorPool.generated_pool.lookup(proto_full_ident)&.msgclass end |
#proto_full_ident ⇒ Object
154 155 156 |
# File 'lib/protod/interpreter.rb', line 154 def proto_full_ident [parent&.full_ident, proto_ident].compact.join('.').presence end |
#proto_ident ⇒ Object
158 159 160 |
# File 'lib/protod/interpreter.rb', line 158 def proto_ident Protod::Proto::Ident.build_from(const.name) end |
#proto_message ⇒ Object
162 163 164 |
# File 'lib/protod/interpreter.rb', line 162 def nil end |
#proto_path ⇒ Object
150 151 152 |
# File 'lib/protod/interpreter.rb', line 150 def proto_path @path || package&.proto_path end |
#set_parent(v) ⇒ Object
139 140 141 142 |
# File 'lib/protod/interpreter.rb', line 139 def set_parent(v) raise ArgumentError, "Can't set parent #{v.full_ident} for #{proto_ident} as #{const.name} : already set #{parent.full_ident}" unless parent.nil? @parent = v end |
#to_pb_from(rb) ⇒ Object
171 172 173 |
# File 'lib/protod/interpreter.rb', line 171 def to_pb_from(rb) raise NotImplementedError, "You need to implement #{__method__} for #{const.name}" end |
#to_rb_from(pb) ⇒ Object
175 176 177 |
# File 'lib/protod/interpreter.rb', line 175 def to_rb_from(pb) raise NotImplementedError, "You need to implement #{__method__} for #{const.name}" end |