Class: Lutaml::Model::TypeSubstitution Private
- Inherits:
-
Object
- Object
- Lutaml::Model::TypeSubstitution
- Defined in:
- lib/lutaml/model/type_substitution.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
TypeSubstitution represents a single type substitution rule.
This is an INTERNAL class. Users should use Register and GlobalRegister.
Responsibility: Represent an immutable type substitution
(from_type => to_type)
This is a Value Object:
-
Immutable after creation
-
Equality based on from_type and to_type
-
NO knowledge of where substitutions are stored
-
NO knowledge of substitution chains
Instance Attribute Summary collapse
-
#from_type ⇒ Class
readonly
private
The type to substitute from.
-
#to_type ⇒ Class
readonly
private
The type to substitute to.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
private
Value object equality.
-
#applies_to?(klass) ⇒ Boolean
private
Check if this substitution applies to the given class.
-
#apply(klass) ⇒ Class?
private
Apply this substitution to a class.
-
#hash ⇒ Integer
private
Hash code for use as hash key.
-
#initialize(from_type:, to_type:) ⇒ TypeSubstitution
constructor
private
Create a new type substitution rule.
-
#to_s ⇒ String
(also: #inspect)
private
Human-readable representation.
-
#with(from_type: self.from_type, to_type: self.to_type) ⇒ TypeSubstitution
private
Create a copy with potentially different values.
Constructor Details
#initialize(from_type:, to_type:) ⇒ TypeSubstitution
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new type substitution rule
46 47 48 49 50 |
# File 'lib/lutaml/model/type_substitution.rb', line 46 def initialize(from_type:, to_type:) @from_type = from_type @to_type = to_type freeze end |
Instance Attribute Details
#from_type ⇒ Class (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The type to substitute from.
31 32 33 |
# File 'lib/lutaml/model/type_substitution.rb', line 31 def from_type @from_type end |
#to_type ⇒ Class (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns The type to substitute to.
34 35 36 |
# File 'lib/lutaml/model/type_substitution.rb', line 34 def to_type @to_type end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Value object equality
Two TypeSubstitutions are equal if they have the same from_type and to_type
83 84 85 86 87 |
# File 'lib/lutaml/model/type_substitution.rb', line 83 def ==(other) return false unless other.is_a?(TypeSubstitution) from_type == other.from_type && to_type == other.to_type end |
#applies_to?(klass) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if this substitution applies to the given class
60 61 62 |
# File 'lib/lutaml/model/type_substitution.rb', line 60 def applies_to?(klass) klass == from_type end |
#apply(klass) ⇒ Class?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Apply this substitution to a class
72 73 74 |
# File 'lib/lutaml/model/type_substitution.rb', line 72 def apply(klass) applies_to?(klass) ? to_type : nil end |
#hash ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hash code for use as hash key
94 95 96 |
# File 'lib/lutaml/model/type_substitution.rb', line 94 def hash [from_type, to_type].hash end |
#to_s ⇒ String Also known as: inspect
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Human-readable representation
101 102 103 |
# File 'lib/lutaml/model/type_substitution.rb', line 101 def to_s "#<#{self.class.name} #{from_type} => #{to_type}>" end |
#with(from_type: self.from_type, to_type: self.to_type) ⇒ TypeSubstitution
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a copy with potentially different values
112 113 114 |
# File 'lib/lutaml/model/type_substitution.rb', line 112 def with(from_type: self.from_type, to_type: self.to_type) self.class.new(from_type: from_type, to_type: to_type) end |