Class: Expressir::Changes::SchemaChange

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/expressir/changes/schema_change.rb

Overview

Represents changes to an EXPRESS schema across multiple versions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_file(path) ⇒ SchemaChange

Load a SchemaChange from a YAML file

Parameters:

  • Path to the YAML file

Returns:

  • The loaded schema changes



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/expressir/changes/schema_change.rb', line 20

def from_file(path)
  content = File.read(path)
  # Handle empty or minimal YAML files
  # Skip leading comments and empty lines
  lines = content.lines
  yaml_start_index = lines.find_index do |line|
    !line.strip.start_with?("#") && !line.strip.empty?
  end

  if yaml_start_index
    content = lines[yaml_start_index..].join
  end

  return new if content.strip == "---" || content.strip.empty?

  from_yaml(content)
end

Instance Method Details

#add_or_update_version(version, description, changes) ⇒ VersionChange

Add or update a change version in this schema

Parameters:

  • Version number

  • Description of changes

  • Hash with :additions, :modifications, :deletions

Returns:

  • The added or updated version



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/expressir/changes/schema_change.rb', line 45

def add_or_update_version(version, description, changes)
  # Initialize versions array if nil
  self.versions ||= []

  # Find existing version with this version
  existing_index = versions.find_index do |ed|
    ed.version == version
  end

  # Create new version
  version = VersionChange.new(
    version: version,
    description: description,
    additions: changes[:additions] || [],
    modifications: changes[:modifications] || [],
    deletions: changes[:deletions] || [],
  )

  if existing_index
    # Replace existing version with same version
    versions[existing_index] = version
  else
    # Add new version
    versions << version
  end

  version
end

#to_file(path) ⇒ Integer

Save this SchemaChange to a YAML file

Parameters:

  • Path where to save the file

Returns:

  • Number of bytes written



78
79
80
81
82
# File 'lib/expressir/changes/schema_change.rb', line 78

def to_file(path)
  # Add schema hint for editor support
  content = "# yaml-language-server: $schema=https://www.expresslang.org/schemas/changes/v1/schema_changes.yaml\n#{to_yaml}"
  File.write(path, content)
end