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 (String)

    Path to the YAML file

Returns:



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

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 (String)

    Version number

  • description (String)

    Description of changes

  • changes (Hash)

    Hash with :additions, :modifications, :deletions

Returns:



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
73
74
75
# File 'lib/expressir/changes/schema_change.rb', line 48

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 (String)

    Path where to save the file

Returns:

  • (Integer)

    Number of bytes written



81
82
83
84
85
# File 'lib/expressir/changes/schema_change.rb', line 81

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