Class: Suma::CollectionManifest

Inherits:
Metanorma::Collection::Config::Manifest
  • Object
show all
Defined in:
lib/suma/collection_manifest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#schema_configObject

attribute :schema_source, Lutaml::Model::Type::String



12
13
14
# File 'lib/suma/collection_manifest.rb', line 12

def schema_config
  @schema_config
end

Instance Method Details

#added_collection_manifestObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/suma/collection_manifest.rb', line 114

def added_collection_manifest
  doc = CollectionConfig.from_file(file)
  doc_id = doc.bibdata.id

  # we need to separate this file from the following new entries
  added = CollectionManifest.new(
    title: "Collection",
    type: "collection",
    identifier: "#{identifier}_",
  )

  added.entry = [
    CollectionManifest.new(
      title: doc_id,
      type: "document",
      entry: entries,
    ),
  ]

  added
end

#docref_from_yaml(model, value) ⇒ Object



33
34
35
# File 'lib/suma/collection_manifest.rb', line 33

def docref_from_yaml(model, value)
  model.entry = CollectionManifest.from_yaml(value.to_yaml)
end

#entries(schema_output_path) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/suma/collection_manifest.rb', line 101

def entries(schema_output_path)
  @schema_config.schemas.map do |schema|
    fname = [File.basename(schema.path, ".exp"), ".xml"].join

    CollectionManifest.new(
      identifier: schema.id,
      title: schema.id,
      file: File.join(schema_output_path, schema.id, "doc_#{fname}"),
      # schema_source: schema.path
    )
  end
end

#expand_schemas_only(schema_output_path) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/suma/collection_manifest.rb', line 80

def expand_schemas_only(schema_output_path)
  return process_entry(schema_output_path) unless file

  update_schema_config

  return process_entry(schema_output_path) unless schemas_only

  # If we are going to keep the schemas-only file and compile it, we can't
  # have it showing up in output.
  self.index = false

  [self, added_collection_manifest]
end

#export_schema_config(path) ⇒ Expressir::SchemaManifest

Recursively exports schema configuration by traversing collection manifests.

This method builds an EXPRESS Schema Manifest (Expressir::SchemaManifest) by:

  1. Starting with an empty or existing Expressir::SchemaManifest

  2. Recursively traversing child entries to collect schemas

  3. Using Expressir::SchemaManifest#concat to combine manifests

The actual schema manifest operations (creation, concatenation, serialization) are handled by Expressir’s SchemaManifest class, keeping the logic DRY.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/suma/collection_manifest.rb', line 49

def export_schema_config(path)
  export_config = @schema_config || Expressir::SchemaManifest.new
  return export_config unless entry

  entry.each do |x|
    child_config = x.export_schema_config(path)
    # Use Expressir's concat method to combine schema manifests
    export_config.concat(child_config) if child_config
  end

  export_config
end

#lookup(attr_sym, match) ⇒ Object



62
63
64
65
66
# File 'lib/suma/collection_manifest.rb', line 62

def lookup(attr_sym, match)
  results = entry.select { |e| e.send(attr_sym) == match }
  results << self if send(attr_sym) == match
  results
end

#process_entry(schema_output_path) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/suma/collection_manifest.rb', line 68

def process_entry(schema_output_path)
  return [self] unless entry

  ret = entry.each_with_object([]) do |e, m|
    add = e.expand_schemas_only(schema_output_path)
    m.concat(add)
  end

  self.entry = ret
  [self]
end

#remove_schemas_only_sourcesObject



94
95
96
97
98
99
# File 'lib/suma/collection_manifest.rb', line 94

def remove_schemas_only_sources
  ret = entry.each_with_object([]) do |e, m|
    e.schemas_only or m << e
  end
  self.entry = ret
end

#update_schema_configObject



136
137
138
139
140
141
142
143
144
145
# File 'lib/suma/collection_manifest.rb', line 136

def update_schema_config
  # If there is collection.yml, this is a document collection, we process
  # schemas.yaml.
  if File.basename(file) == "collection.yml"
    schemas_yaml_path = File.join(File.dirname(file), "schemas.yaml")
    if schemas_yaml_path && File.exist?(schemas_yaml_path)
      @schema_config = Expressir::SchemaManifest.from_file(schemas_yaml_path)
    end
  end
end