Class: Protod::Proto::Part
- Inherits:
-
Object
- Object
- Protod::Proto::Part
show all
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- lib/protod/proto/part.rb
Instance Method Summary
collapse
Instance Method Details
#ancestor_as(part_const) ⇒ Object
25
26
27
|
# File 'lib/protod/proto/part.rb', line 25
def ancestor_as(part_const)
parent.is_a?(part_const) ? parent : parent&.ancestor_as(part_const)
end
|
#freeze ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/protod/proto/part.rb', line 50
def freeze
super.tap do
(attributes.keys - %w[parent]).each do |attribute_name|
value = attributes.fetch(attribute_name)
value.freeze
value.each(&:freeze) if value.is_a?(::Array)
end
end
end
|
#has?(part, in_the:) ⇒ Boolean
42
43
44
|
# File 'lib/protod/proto/part.rb', line 42
def has?(part, in_the:)
public_send(in_the).any? { _1.ident == part.ident }
end
|
#ident=(value) ⇒ Object
15
16
17
18
19
|
# File 'lib/protod/proto/part.rb', line 15
def ident=(value)
super(Protod::Proto::Ident.build_from(value.to_s))
raise ArgumentError, "Invalid grpc ident : #{value}. see https://protobuf.dev/reference/protobuf/proto3-spec/#identifiers" unless ident&.match(/\A[a-zA-Z][a-zA-Z0-9_]*\z/)
end
|
#push(part, into:, ignore: false) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/protod/proto/part.rb', line 29
def push(part, into:, ignore: false)
already_pushed = has?(part, in_the: into)
raise ArgumentError, "Can't push already present #{part.ident} in #{ident}" if already_pushed && ignore.!
raise ArgumentError, "Can't push already bound to #{part.parent.ident} in #{ident}" if part.parent
part.assign_attributes(parent: self)
public_send(into).push(part) unless already_pushed
part
end
|
#root ⇒ Object
21
22
23
|
# File 'lib/protod/proto/part.rb', line 21
def root
parent ? parent.root : self
end
|
#to_proto ⇒ Object
46
47
48
|
# File 'lib/protod/proto/part.rb', line 46
def to_proto
raise NotImplementedError, "Not defined #{self.class.name}##{__method__}"
end
|