Class: Ukiryu::Definition::Sources::StringSource

Inherits:
Ukiryu::Definition::Source show all
Defined in:
lib/ukiryu/definition/sources/string.rb

Overview

Load tool definitions from a YAML string

This source handles YAML content provided directly as a string, useful for definitions obtained via command-line flags or programmatic generation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Ukiryu::Definition::Source

#==, #hash, #inspect, #to_s

Constructor Details

#initialize(content) ⇒ StringSource

Create a new string-based definition source

Parameters:

  • content (String)

    the YAML content

Raises:

  • (ArgumentError)

    if content is not a String

  • (DefinitionLoadError)

    if content is empty



25
26
27
28
# File 'lib/ukiryu/definition/sources/string.rb', line 25

def initialize(content)
  @content = validate_content!(content)
  @content_hash = sha256(@content)
end

Instance Attribute Details

#contentString (readonly)

The YAML content

Returns:

  • (String)

    the YAML string



14
15
16
# File 'lib/ukiryu/definition/sources/string.rb', line 14

def content
  @content
end

#content_hashString (readonly)

The SHA256 hash of the content

Returns:

  • (String)

    hexadecimal hash



18
19
20
# File 'lib/ukiryu/definition/sources/string.rb', line 18

def content_hash
  @content_hash
end

Instance Method Details

#cache_keyString

Get a unique cache key for this string source

The cache key is based on the SHA256 hash of the content, ensuring identical strings produce identical cache keys.

Returns:

  • (String)

    unique cache key



50
51
52
# File 'lib/ukiryu/definition/sources/string.rb', line 50

def cache_key
  "string:#{content_hash}"
end

#loadString

Load the YAML definition content

Returns:

  • (String)

    the YAML content



33
34
35
# File 'lib/ukiryu/definition/sources/string.rb', line 33

def load
  @content
end

#sizeInteger

Get the size of the content in bytes

Returns:

  • (Integer)

    content size



57
58
59
# File 'lib/ukiryu/definition/sources/string.rb', line 57

def size
  @content.bytesize
end

#source_typeSymbol

Get the source type

Returns:

  • (Symbol)

    :string



40
41
42
# File 'lib/ukiryu/definition/sources/string.rb', line 40

def source_type
  :string
end