Class: ComplyanceSDK::Models::SourceRef
- Inherits:
-
Object
- Object
- ComplyanceSDK::Models::SourceRef
- Defined in:
- lib/complyance_sdk/models/source_ref.rb
Overview
Reference to a source using name and version (simplified identity) This replaces the need for source ID bookkeeping on the client side
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.from_h(hash) ⇒ SourceRef
Create from hash.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Equality comparison.
-
#hash ⇒ Integer
Hash code for equality.
-
#identity ⇒ String
Get the identity string (name:version).
-
#initialize(name, version, type = :first_party) ⇒ SourceRef
constructor
Initialize a new source reference.
-
#inspect ⇒ String
Inspect representation.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_json_hash ⇒ Hash
Convert to JSON-compatible hash (for API requests).
-
#to_s ⇒ String
String representation.
-
#valid? ⇒ Boolean
Validate the source reference.
-
#validate! ⇒ Object
Check if source reference is valid, raise error if not.
-
#validation_errors ⇒ Array<String>
Get validation errors.
Constructor Details
#initialize(name, version, type = :first_party) ⇒ SourceRef
Initialize a new source reference
16 17 18 19 20 21 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 16 def initialize(name, version, type = :first_party) # Allow empty values for mapping purposes @name = name.nil? ? '' : name.to_s.strip @version = version.nil? ? '' : version.to_s.strip @type = type end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 8 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 8 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
8 9 10 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 8 def version @version end |
Class Method Details
.from_h(hash) ⇒ SourceRef
Create from hash
61 62 63 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 61 def self.from_h(hash) new(hash[:name] || hash['name'], hash[:version] || hash['version']) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Equality comparison
83 84 85 86 87 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 83 def ==(other) return false unless other.is_a?(SourceRef) @name == other.name && @version == other.version end |
#hash ⇒ Integer
Hash code for equality
92 93 94 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 92 def hash [@name, @version].hash end |
#identity ⇒ String
Get the identity string (name:version)
26 27 28 29 30 31 32 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 26 def identity if @name.empty? && @version.empty? "mapping:unknown" else "#{@name}:#{@version}" end end |
#inspect ⇒ String
Inspect representation
75 76 77 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 75 def inspect "#<#{self.class.name}:#{object_id} name=#{@name.inspect} version=#{@version.inspect}>" end |
#to_h ⇒ Hash
Convert to hash representation
37 38 39 40 41 42 43 44 45 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 37 def to_h { name: @name, version: @version, type: @type.to_s.upcase, identity: identity, id: identity } end |
#to_json_hash ⇒ Hash
Convert to JSON-compatible hash (for API requests)
50 51 52 53 54 55 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 50 def to_json_hash { 'name' => @name, 'version' => @version } end |
#to_s ⇒ String
String representation
68 69 70 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 68 def to_s identity end |
#valid? ⇒ Boolean
Validate the source reference
102 103 104 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 102 def valid? !@name.empty? && !@version.empty? end |
#validate! ⇒ Object
Check if source reference is valid, raise error if not
119 120 121 122 123 124 125 126 127 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 119 def validate! return true if valid? = validation_errors.join(', ') raise ComplyanceSDK::Exceptions::ValidationError.new( "Invalid source reference: #{}", context: { name: @name, version: @version } ) end |
#validation_errors ⇒ Array<String>
Get validation errors
109 110 111 112 113 114 |
# File 'lib/complyance_sdk/models/source_ref.rb', line 109 def validation_errors errors = [] errors << 'Name cannot be blank' if @name.empty? errors << 'Version cannot be blank' if @version.empty? errors end |