Class: Ukiryu::Definition::Sources::FileSource
- Inherits:
-
Ukiryu::Definition::Source
- Object
- Ukiryu::Definition::Source
- Ukiryu::Definition::Sources::FileSource
- Defined in:
- lib/ukiryu/definition/sources/file.rb
Overview
Load tool definitions from a file
This source reads YAML tool definitions from the filesystem. It tracks file metadata for cache invalidation.
Instance Attribute Summary collapse
-
#mtime ⇒ Time
readonly
The file modification time.
-
#path ⇒ String
readonly
The path to the definition file.
Instance Method Summary collapse
-
#cache_key ⇒ String
Get a unique cache key for this file source.
-
#initialize(path) ⇒ FileSource
constructor
Create a new file-based definition source.
-
#load ⇒ String
Load the YAML definition content from the file.
-
#real_path ⇒ String
Get the real path (resolves symlinks).
-
#source_type ⇒ Symbol
Get the source type.
Methods inherited from Ukiryu::Definition::Source
Constructor Details
#initialize(path) ⇒ FileSource
Create a new file-based definition source
24 25 26 27 28 29 30 31 |
# File 'lib/ukiryu/definition/sources/file.rb', line 24 def initialize(path) @path = (path) @mtime = nil # Will be set on first load @cached_content = nil validate_file_exists! validate_file_readable! end |
Instance Attribute Details
#mtime ⇒ Time (readonly)
The file modification time
17 18 19 |
# File 'lib/ukiryu/definition/sources/file.rb', line 17 def mtime @mtime end |
#path ⇒ String (readonly)
The path to the definition file
13 14 15 |
# File 'lib/ukiryu/definition/sources/file.rb', line 13 def path @path end |
Instance Method Details
#cache_key ⇒ String
Get a unique cache key for this file source
The cache key includes a hash of the path and the mtime, ensuring that file changes invalidate the cache.
66 67 68 |
# File 'lib/ukiryu/definition/sources/file.rb', line 66 def cache_key "file:#{sha256(path)}:#{mtime || get_mtime}" end |
#load ⇒ String
Load the YAML definition content from the file
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ukiryu/definition/sources/file.rb', line 37 def load current_mtime = get_mtime # Check if file has changed since init if @mtime && @mtime != current_mtime raise Ukiryu::Errors::DefinitionLoadError, "File #{@path} has been modified since it was loaded. " \ "Original mtime: #{@mtime}, Current mtime: #{current_mtime}" end @mtime = current_mtime # Read and cache content @load ||= read_file end |
#real_path ⇒ String
Get the real path (resolves symlinks)
73 74 75 76 77 |
# File 'lib/ukiryu/definition/sources/file.rb', line 73 def real_path @real_path ||= File.realpath(path) rescue Errno::ENOENT path end |
#source_type ⇒ Symbol
Get the source type
56 57 58 |
# File 'lib/ukiryu/definition/sources/file.rb', line 56 def source_type :file end |