Class: Ukiryu::Definition::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/definition/loader.rb

Overview

Loader for tool definitions from various sources

The loader orchestrates loading tool definitions from different sources (files, strings, bundled locations, register) and provides a unified interface for definition loading.

Class Method Summary collapse

Class Method Details

.clear_cache(source = nil) ⇒ Object

Clear the profile cache

Parameters:

  • source (Source, nil) (defaults to: nil)

    clear specific source or all if nil



73
74
75
76
77
78
79
# File 'lib/ukiryu/definition/loader.rb', line 73

def clear_cache(source = nil)
  if source
    profile_cache.delete(source.cache_key)
  else
    profile_cache.clear
  end
end

.load_from_file(path, options = {}) ⇒ Models::ToolDefinition

Load a tool definition from a file path

Parameters:

  • path (String)

    path to the definition file

  • options (Hash) (defaults to: {})

    loading options

Returns:



48
49
50
51
# File 'lib/ukiryu/definition/loader.rb', line 48

def load_from_file(path, options = {})
  source = Sources::FileSource.new(path)
  load_from_source(source, options)
end

.load_from_source(source, options = {}) ⇒ Models::ToolDefinition

Load a tool definition from a source

Parameters:

  • source (Source)

    the definition source

  • options (Hash) (defaults to: {})

    loading options

Options Hash (options):

  • :validation (Symbol)

    validation mode (:strict, :lenient, :none)

Returns:

Raises:

  • (DefinitionLoadError)

    if loading fails



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ukiryu/definition/loader.rb', line 19

def load_from_source(source, options = {})
  # Check cache first
  cache_key = source.cache_key
  return profile_cache[cache_key] if profile_cache.key?(cache_key)

  # Load YAML content from source
  yaml_content = source.load

  # Parse using lutaml-model
  profile = parse_yaml(yaml_content, source)

  # Validate if requested
  validation_mode = options[:validation] || :strict
  validate_profile(profile, validation_mode) if validation_mode != :none

  # Resolve profile inheritance (merges parent commands into child profiles)
  profile.resolve_inheritance!

  # Cache the profile
  profile_cache[cache_key] = profile

  profile
end

.load_from_string(yaml_string, options = {}) ⇒ Models::ToolDefinition

Load a tool definition from a YAML string

Parameters:

  • yaml_string (String)

    the YAML content

  • options (Hash) (defaults to: {})

    loading options

Returns:



58
59
60
61
# File 'lib/ukiryu/definition/loader.rb', line 58

def load_from_string(yaml_string, options = {})
  source = Sources::StringSource.new(yaml_string)
  load_from_source(source, options)
end

.profile_cacheCache

Get the profile cache (bounded LRU cache)

Returns:

  • (Cache)

    the profile cache



66
67
68
# File 'lib/ukiryu/definition/loader.rb', line 66

def profile_cache
  @profile_cache ||= Cache.new(max_size: 100, ttl: 3600)
end