Class: RosettAi::Provenance::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/provenance/source.rb

Overview

Classifies the source type of an AI contribution.

Source types track where AI-generated code drew its knowledge from, enabling license traceability and compliance auditing.

Constant Summary collapse

ALLOWED_TYPES =
[
  'library_api',
  'project_code',
  'documentation',
  'pattern',
  'external_source'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, reference:, url: nil) ⇒ Source

Returns a new instance of Source.

Parameters:

  • type (String)
  • reference (String)

    human-readable description of the source

  • url (String, nil) (defaults to: nil)

    URL for external_source type

Raises:

  • (ArgumentError)

    if type is not in ALLOWED_TYPES

  • (ArgumentError)

    if external_source has bare domain URL



28
29
30
31
32
33
34
35
# File 'lib/rosett_ai/provenance/source.rb', line 28

def initialize(type:, reference:, url: nil)
  validate_type!(type)
  validate_url!(type, url)

  @type = type.freeze
  @reference = reference.freeze
  @url = url&.freeze
end

Instance Attribute Details

#referenceObject (readonly)

Returns the value of attribute reference.



21
22
23
# File 'lib/rosett_ai/provenance/source.rb', line 21

def reference
  @reference
end

#typeObject (readonly)

Returns the value of attribute type.



21
22
23
# File 'lib/rosett_ai/provenance/source.rb', line 21

def type
  @type
end

#urlObject (readonly)

Returns the value of attribute url.



21
22
23
# File 'lib/rosett_ai/provenance/source.rb', line 21

def url
  @url
end

Instance Method Details

#to_hHash

Returns serializable representation.

Returns:

  • (Hash)

    serializable representation



38
39
40
41
42
# File 'lib/rosett_ai/provenance/source.rb', line 38

def to_h
  hash = { 'type' => @type, 'reference' => @reference }
  hash['url'] = @url if @url
  hash
end