Class: Suma::CollectionManifest
- Inherits:
-
Metanorma::Collection::Config::Manifest
- Object
- Metanorma::Collection::Config::Manifest
- Suma::CollectionManifest
- Defined in:
- lib/suma/collection_manifest.rb
Instance Attribute Summary collapse
-
#schema_config ⇒ Object
Returns the value of attribute schema_config.
Instance Method Summary collapse
- #added_collection_manifest(schema_output_path) ⇒ Object
- #docref_from_yaml(model, value) ⇒ Object
- #entries(schema_output_path) ⇒ Object
- #expand_schemas_only(schema_output_path) ⇒ Object
-
#export_schema_config(path) ⇒ Expressir::SchemaManifest
Recursively exports schema configuration by traversing collection manifests.
- #lookup_schemas_only ⇒ Object
- #process_entry(schema_output_path) ⇒ Object
- #remove_schemas_only_sources ⇒ Object
- #update_schema_config ⇒ Object
Instance Attribute Details
#schema_config ⇒ Object
Returns the value of attribute schema_config.
11 12 13 |
# File 'lib/suma/collection_manifest.rb', line 11 def schema_config @schema_config end |
Instance Method Details
#added_collection_manifest(schema_output_path) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/suma/collection_manifest.rb', line 113 def added_collection_manifest(schema_output_path) 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(schema_output_path), ), ] added end |
#docref_from_yaml(model, value) ⇒ Object
32 33 34 |
# File 'lib/suma/collection_manifest.rb', line 32 def docref_from_yaml(model, value) model.entry = CollectionManifest.from_yaml(value.to_yaml) end |
#entries(schema_output_path) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/suma/collection_manifest.rb', line 100 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
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/suma/collection_manifest.rb', line 79 def (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(schema_output_path)] 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:
-
Starting with an empty or existing Expressir::SchemaManifest
-
Recursively traversing child entries to collect schemas
-
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.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/suma/collection_manifest.rb', line 48 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_schemas_only ⇒ Object
61 62 63 64 65 |
# File 'lib/suma/collection_manifest.rb', line 61 def lookup_schemas_only results = entry.select(&:schemas_only) results << self if schemas_only results end |
#process_entry(schema_output_path) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/suma/collection_manifest.rb', line 67 def process_entry(schema_output_path) return [self] unless entry ret = entry.each_with_object([]) do |e, m| add = e.(schema_output_path) m.concat(add) end self.entry = ret [self] end |
#remove_schemas_only_sources ⇒ Object
93 94 95 96 97 98 |
# File 'lib/suma/collection_manifest.rb', line 93 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_config ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/suma/collection_manifest.rb', line 135 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 |