Class: Lutaml::Xsd::SchemaRepositoryMetadata

Inherits:
Model::Serializable
  • Object
show all
Defined in:
lib/lutaml/xsd/schema_repository_metadata.rb

Overview

Metadata for a schema repository package

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_repository(repository, additional = {}) ⇒ SchemaRepositoryMetadata

Create metadata from a repository

Parameters:

  • repository (SchemaRepository)

    Repository instance

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

    Additional metadata fields

Returns:



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/lutaml/xsd/schema_repository_metadata.rb', line 125

def self.from_repository(repository, additional = {})
  # Extract known fields
   = new(
    files: repository.files || [],
    schema_location_mappings: repository.schema_location_mappings || [],
    namespace_mappings: repository.namespace_mappings || [],
    statistics: SchemaRepositoryStatistics.from_statistics(repository.statistics),
    created_at: Time.now.iso8601,
    lutaml_xsd_version: Lutaml::Xsd::VERSION,
    name: additional[:name] || additional["name"],
    version: additional[:version] || additional["version"],
    description: additional[:description] || additional["description"],
    created_by: additional[:created_by] || additional["created_by"],
  )

  # Store any custom metadata fields as instance variables
  known_fields = [:name, :version, :description, :created_by,
                  "name", "version", "description", "created_by"]
  additional.each do |key, value|
    next if known_fields.include?(key)

    # Set as instance variable to be picked up by to_yaml/to_hash
    .instance_variable_set("@#{key}", value)
  end

  
end

Instance Method Details

#to_hashObject

Override to_hash to include extra fields



108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/lutaml/xsd/schema_repository_metadata.rb', line 108

def to_hash
  hash = super
  # Add any instance variables that aren't part of the schema
  instance_variables.each do |ivar|
    var_name = ivar.to_s.delete_prefix("@")
    next if hash.key?(var_name) || hash.key?(var_name.to_sym)

    value = instance_variable_get(ivar)
    hash[var_name] = value unless value.nil?
  end
  hash
end

#to_yamlObject

Override to_yaml to include any extra custom metadata fields



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/lutaml/xsd/schema_repository_metadata.rb', line 94

def to_yaml(*)
  hash = to_hash
  # Add any instance variables that aren't part of the schema
  instance_variables.each do |ivar|
    var_name = ivar.to_s.delete_prefix("@")
    next if hash.key?(var_name) || hash.key?(var_name.to_sym)

    value = instance_variable_get(ivar)
    hash[var_name] = value unless value.nil?
  end
  hash.to_yaml(*)
end