Class: OpenUSD::RelationshipSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/openusd/relationship_spec.rb

Overview

An authored relationship in a Layer.

Constant Summary collapse

UNAUTHORED =

Sentinel distinguishing no target opinion from an authored empty list.

Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, targets: UNAUTHORED, custom: false, metadata: {}) ⇒ RelationshipSpec

Returns a new instance of RelationshipSpec.



12
13
14
15
16
17
18
19
# File 'lib/openusd/relationship_spec.rb', line 12

def initialize(name, targets: UNAUTHORED, custom: false, metadata: {})
  @name = validate_name(name)
  @custom = custom == true
  @metadata = .dup
  @targets = []
  @targets_authored = false
  self.targets = targets unless targets.equal?(UNAUTHORED)
end

Instance Attribute Details

#customObject

Returns the value of attribute custom.



10
11
12
# File 'lib/openusd/relationship_spec.rb', line 10

def custom
  @custom
end

#metadataObject (readonly)

Returns the value of attribute metadata.



9
10
11
# File 'lib/openusd/relationship_spec.rb', line 9

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/openusd/relationship_spec.rb', line 9

def name
  @name
end

#targetsObject

Returns the value of attribute targets.



9
10
11
# File 'lib/openusd/relationship_spec.rb', line 9

def targets
  @targets
end

Instance Method Details

#add_target(path) ⇒ Path

Add a target unless it is already present.

Returns:



33
34
35
36
37
38
# File 'lib/openusd/relationship_spec.rb', line 33

def add_target(path)
  target = Path.parse(path)
  @targets << target unless @targets.include?(target)
  @targets_authored = true
  target
end

#targets_authored?Boolean

Whether targets, including an empty list, are authored.

Returns:

  • (Boolean)


27
28
29
# File 'lib/openusd/relationship_spec.rb', line 27

def targets_authored?
  @targets_authored
end

#to_hHash

Returns semantic representation used for equality.

Returns:

  • (Hash)

    semantic representation used for equality



41
42
43
44
45
46
# File 'lib/openusd/relationship_spec.rb', line 41

def to_h
  {
    name: name, targets: targets, targets_authored: targets_authored?,
    custom: custom, metadata: 
  }
end