Class: OpenUSD::PrimSpec
- Inherits:
-
Object
- Object
- OpenUSD::PrimSpec
- Defined in:
- lib/openusd/prim_spec.rb
Overview
An authored prim specification in a Layer.
Constant Summary collapse
- SPECIFIERS =
Valid authored specifier values.
%i[def over class].freeze
- REFERENCES_UNAUTHORED =
Sentinel distinguishing no reference opinion from an authored empty list.
Object.new.freeze
- REFERENCE_LIST_OPERATIONS =
Supported reference list-edit operators.
%i[prepend append delete reorder add explicit].freeze
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#reference_list_op ⇒ Object
readonly
Returns the value of attribute reference_list_op.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
-
#specifier ⇒ Object
Returns the value of attribute specifier.
-
#type_name ⇒ Object
Returns the value of attribute type_name.
-
#variant_sets ⇒ Object
readonly
Returns the value of attribute variant_sets.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #add_property(property) ⇒ Object
-
#add_reference(asset_path = nil, prim_path = nil) ⇒ Reference
Add a reference composition arc.
-
#child_named(name) ⇒ PrimSpec?
Direct child by name.
-
#each_descendant(&block) ⇒ Enumerator?
Traverse authored descendants depth-first.
-
#initialize(name, type_name: nil, specifier: :def, metadata: {}, references: REFERENCES_UNAUTHORED, reference_list_op: :prepend) ⇒ PrimSpec
constructor
A new instance of PrimSpec.
-
#path ⇒ Object
Absolute path within the containing layer.
-
#property_named(name) ⇒ AttributeSpec, ...
Authored property by name.
-
#references_authored? ⇒ Boolean
Whether a reference opinion, including an empty list, is authored.
-
#remove_child(name) ⇒ PrimSpec?
Remove a direct child by name.
-
#remove_property(name) ⇒ AttributeSpec, ...
Remove an authored property by name.
-
#set_references(values, operation: nil) ⇒ Array<Reference>
Replace the authored references and list-edit operation.
-
#to_h ⇒ Hash
Semantic representation used for equality.
Constructor Details
#initialize(name, type_name: nil, specifier: :def, metadata: {}, references: REFERENCES_UNAUTHORED, reference_list_op: :prepend) ⇒ PrimSpec
Returns a new instance of PrimSpec.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openusd/prim_spec.rb', line 17 def initialize(name, type_name: nil, specifier: :def, metadata: {}, references: REFERENCES_UNAUTHORED, reference_list_op: :prepend) @name = validate_name(name) @type_name = type_name&.to_s self.specifier = specifier @metadata = .dup @references = [] @references_authored = false set_references(references, operation: reference_list_op) unless references.equal?(REFERENCES_UNAUTHORED) @variant_sets = {} @children = [] @child_index = {} @properties = [] @property_index = {} @parent = nil end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def children @children end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
15 16 17 |
# File 'lib/openusd/prim_spec.rb', line 15 def parent @parent end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def properties @properties end |
#reference_list_op ⇒ Object (readonly)
Returns the value of attribute reference_list_op.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def reference_list_op @reference_list_op end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def references @references end |
#specifier ⇒ Object
Returns the value of attribute specifier.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def specifier @specifier end |
#type_name ⇒ Object
Returns the value of attribute type_name.
15 16 17 |
# File 'lib/openusd/prim_spec.rb', line 15 def type_name @type_name end |
#variant_sets ⇒ Object (readonly)
Returns the value of attribute variant_sets.
13 14 15 |
# File 'lib/openusd/prim_spec.rb', line 13 def variant_sets @variant_sets end |
Instance Method Details
#add_child(child) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/openusd/prim_spec.rb', line 48 def add_child(child) raise OpenUSD::TypeError, "child must be a PrimSpec" unless child.is_a?(PrimSpec) raise PathError, "duplicate child prim: #{child.name}" if @child_index.key?(child.name) child.parent = self children << child @child_index[child.name] = child child end |
#add_property(property) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/openusd/prim_spec.rb', line 75 def add_property(property) valid = property.is_a?(AttributeSpec) || property.is_a?(RelationshipSpec) raise OpenUSD::TypeError, "property must be an AttributeSpec or RelationshipSpec" unless valid raise PathError, "duplicate property: #{property.name}" if @property_index.key?(property.name) properties << property @property_index[property.name] = property property end |
#add_reference(asset_path = nil, prim_path = nil) ⇒ Reference
Add a reference composition arc.
101 102 103 104 105 106 107 |
# File 'lib/openusd/prim_spec.rb', line 101 def add_reference(asset_path = nil, prim_path = nil) reference = Reference.new(asset_path, prim_path) references << reference @references_authored = true @reference_list_op = :prepend if @reference_list_op.nil? reference end |
#child_named(name) ⇒ PrimSpec?
Returns direct child by name.
71 72 73 |
# File 'lib/openusd/prim_spec.rb', line 71 def child_named(name) @child_index[name.to_s] end |
#each_descendant(&block) ⇒ Enumerator?
Traverse authored descendants depth-first.
130 131 132 133 134 135 136 137 |
# File 'lib/openusd/prim_spec.rb', line 130 def each_descendant(&block) return enum_for(__method__) unless block children.each do |child| yield child child.each_descendant(&block) end end |
#path ⇒ Object
Absolute path within the containing layer.
42 43 44 45 46 |
# File 'lib/openusd/prim_spec.rb', line 42 def path return Path.parse("/#{name}") unless parent parent.path.child(name) end |
#property_named(name) ⇒ AttributeSpec, ...
Returns authored property by name.
86 87 88 |
# File 'lib/openusd/prim_spec.rb', line 86 def property_named(name) @property_index[name.to_s] end |
#references_authored? ⇒ Boolean
Whether a reference opinion, including an empty list, is authored.
124 125 126 |
# File 'lib/openusd/prim_spec.rb', line 124 def @references_authored end |
#remove_child(name) ⇒ PrimSpec?
Remove a direct child by name.
60 61 62 63 64 65 66 67 68 |
# File 'lib/openusd/prim_spec.rb', line 60 def remove_child(name) child = child_named(name) return unless child children.delete(child) @child_index.delete(name.to_s) child.parent = nil child end |
#remove_property(name) ⇒ AttributeSpec, ...
Remove an authored property by name.
92 93 94 95 96 97 |
# File 'lib/openusd/prim_spec.rb', line 92 def remove_property(name) property = property_named(name) properties.delete(property) @property_index.delete(name.to_s) property end |
#set_references(values, operation: nil) ⇒ Array<Reference>
Replace the authored references and list-edit operation.
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/openusd/prim_spec.rb', line 111 def set_references(values, operation: nil) normalized_operation = operation&.to_sym unless normalized_operation.nil? || REFERENCE_LIST_OPERATIONS.include?(normalized_operation) raise OpenUSD::TypeError, "invalid reference list operation: #{operation.inspect}" end @references = Array(values).map { |reference| normalize_reference(reference) } @reference_list_op = normalized_operation @references_authored = true references end |
#to_h ⇒ Hash
Returns semantic representation used for equality.
140 141 142 143 144 145 146 147 |
# File 'lib/openusd/prim_spec.rb', line 140 def to_h { name: name, type_name: type_name, specifier: specifier, metadata: , references: references, references_authored: , reference_list_op: reference_list_op, variant_sets: variant_sets_to_h, properties: semantic_properties(properties), children: children.map(&:to_h) } end |