Class: RosettAi::Composition::Lockfile
- Inherits:
-
Object
- Object
- RosettAi::Composition::Lockfile
- Defined in:
- lib/rosett_ai/composition/lockfile.rb
Overview
Manages the .rosett-ai-lock.yml lockfile for reproducible behaviour
composition. Writes the exact composition result so that
--frozen compilations can reproduce the same output.
Constant Summary collapse
- FILENAME =
'.rosett-ai-lock.yml'
Instance Method Summary collapse
-
#exist? ⇒ Boolean
True if the lockfile exists.
-
#fresh?(behaviour_files) ⇒ Boolean
Checks if behaviour files have changed since the lockfile was written.
-
#initialize(root:) ⇒ Lockfile
constructor
A new instance of Lockfile.
-
#path ⇒ Pathname
Full path to the lockfile.
-
#read ⇒ Hash
Reads and parses the lockfile.
-
#write(result, behaviours:) ⇒ Pathname
Writes the lockfile from a CompositionResult.
Constructor Details
Instance Method Details
#exist? ⇒ Boolean
Returns true if the lockfile exists.
28 29 30 |
# File 'lib/rosett_ai/composition/lockfile.rb', line 28 def exist? path.exist? end |
#fresh?(behaviour_files) ⇒ Boolean
Checks if behaviour files have changed since the lockfile was written.
57 58 59 60 61 62 63 64 65 |
# File 'lib/rosett_ai/composition/lockfile.rb', line 57 def fresh?(behaviour_files) return false unless exist? data = read locked_checksums = data.fetch('behaviours', {}) current_checksums = compute_checksums(behaviour_files) locked_checksums == current_checksums end |
#path ⇒ Pathname
Returns full path to the lockfile.
23 24 25 |
# File 'lib/rosett_ai/composition/lockfile.rb', line 23 def path @root.join(FILENAME) end |
#read ⇒ Hash
Reads and parses the lockfile.
47 48 49 50 51 |
# File 'lib/rosett_ai/composition/lockfile.rb', line 47 def read raise RosettAi::CompositionError, "Lockfile not found: #{path}" unless exist? RosettAi::YamlLoader.load_file(path.to_s) end |
#write(result, behaviours:) ⇒ Pathname
Writes the lockfile from a CompositionResult.
37 38 39 40 41 |
# File 'lib/rosett_ai/composition/lockfile.rb', line 37 def write(result, behaviours:) data = build_lockfile_data(result, behaviours) path.write(YAML.dump(data)) path end |