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
attribute :schema_source, Lutaml::Model::Type::String.
Instance Method Summary collapse
- #added_collection_manifest ⇒ Object
- #docref_from_yaml(model, value) ⇒ Object
- #entries(schema_output_path) ⇒ Object
- #expand_schemas_only(schema_output_path) ⇒ Object
- #export_schema_config(path) ⇒ Object
- #lookup(attr_sym, match) ⇒ Object
- #process_entry(schema_output_path) ⇒ Object
- #remove_schemas_only_sources ⇒ Object
- #update_schema_config ⇒ Object
Instance Attribute Details
#schema_config ⇒ Object
attribute :schema_source, Lutaml::Model::Type::String
13 14 15 |
# File 'lib/suma/collection_manifest.rb', line 13 def schema_config @schema_config end |
Instance Method Details
#added_collection_manifest ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/suma/collection_manifest.rb', line 102 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
34 35 36 |
# File 'lib/suma/collection_manifest.rb', line 34 def docref_from_yaml(model, value) model.entry = CollectionManifest.from_yaml(value.to_yaml) end |
#entries(schema_output_path) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/suma/collection_manifest.rb', line 89 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
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/suma/collection_manifest.rb', line 68 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] end |
#export_schema_config(path) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/suma/collection_manifest.rb', line 38 def export_schema_config(path) export_config = @schema_config || Suma::SchemaConfig::Config.new return export_config unless entry entry.each do |x| child_config = x.export_schema_config(path) export_config.concat(child_config) if child_config end export_config end |
#lookup(attr_sym, match) ⇒ Object
50 51 52 53 54 |
# File 'lib/suma/collection_manifest.rb', line 50 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
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/suma/collection_manifest.rb', line 56 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
82 83 84 85 86 87 |
# File 'lib/suma/collection_manifest.rb', line 82 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
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/suma/collection_manifest.rb', line 124 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 = Suma::SchemaConfig::Config.from_file(schemas_yaml_path) end end end |