Class: Protod::Interpreter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/protod/interpreter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#constObject (readonly)

Returns the value of attribute const.



115
116
117
# File 'lib/protod/interpreter.rb', line 115

def const
  @const
end

#parentObject (readonly)

Returns the value of attribute parent.



115
116
117
# File 'lib/protod/interpreter.rb', line 115

def parent
  @parent
end

#pathObject (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

Returns:

  • (Boolean)


127
128
129
130
131
# File 'lib/protod/interpreter.rb', line 127

def bindable?
  return false unless proto_message
  return false if bound?
  true
end

#bound?Boolean

Returns:

  • (Boolean)


133
134
135
136
137
# File 'lib/protod/interpreter.rb', line 133

def bound?
  return false unless proto_message

  parent.nil?.!
end

#packageObject



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_constObject



166
167
168
169
# File 'lib/protod/interpreter.rb', line 166

def pb_const
  proto_message&.pb_const ||
    Google::Protobuf::DescriptorPool.generated_pool.lookup(proto_full_ident)&.msgclass
end

#proto_full_identObject



154
155
156
# File 'lib/protod/interpreter.rb', line 154

def proto_full_ident
  [parent&.full_ident, proto_ident].compact.join('.').presence
end

#proto_identObject



158
159
160
# File 'lib/protod/interpreter.rb', line 158

def proto_ident
  Protod::Proto::Ident.build_from(const.name)
end

#proto_messageObject



162
163
164
# File 'lib/protod/interpreter.rb', line 162

def proto_message
  nil
end

#proto_pathObject



150
151
152
# File 'lib/protod/interpreter.rb', line 150

def proto_path
  @path || package&.proto_path
end

#set_parent(v) ⇒ Object

Raises:

  • (ArgumentError)


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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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