Class: Suma::SchemaDiscovery
- Inherits:
-
Object
- Object
- Suma::SchemaDiscovery
- Defined in:
- lib/suma/schema_discovery.rb
Overview
Service for schema-config I/O on a single CollectionManifest node.
SchemaDiscovery owns two concerns that previously lived on CollectionManifest:
- Loading the
schemas.yamlthat sits next to acollection.ymlinto the manifest'sschema_configslot. - Building the doc CollectionManifest sub-tree that hosts the
compiled XML output for each schema in
schema_config.
It does not walk the manifest tree — that is ManifestTraverser's job. The split keeps schema I/O in one place and tree traversal in another, so each is independently testable.
Instance Attribute Summary collapse
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
Instance Method Summary collapse
-
#build_added_manifest(schema_output_path) ⇒ Object
Build a CollectionManifest sub-tree that hosts the compiled XML for every schema in
manifest.schema_config. -
#build_doc_entries(schema_output_path) ⇒ Object
Build one CollectionManifest per schema in schema_config, naming each output file as
doc_<basename>.xmlunder<schema_output_path>/<schema_id>/. -
#initialize(manifest) ⇒ SchemaDiscovery
constructor
A new instance of SchemaDiscovery.
-
#load_config ⇒ Object
If the manifest's file is a
collection.ymland aschemas.yamlsits alongside it, parse it into an Expressir::SchemaManifest and store it on the manifest.
Constructor Details
#initialize(manifest) ⇒ SchemaDiscovery
Returns a new instance of SchemaDiscovery.
20 21 22 |
# File 'lib/suma/schema_discovery.rb', line 20 def initialize(manifest) @manifest = manifest end |
Instance Attribute Details
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
18 19 20 |
# File 'lib/suma/schema_discovery.rb', line 18 def manifest @manifest end |
Instance Method Details
#build_added_manifest(schema_output_path) ⇒ Object
Build a CollectionManifest sub-tree that hosts the compiled XML for
every schema in manifest.schema_config. The wrapper is named with
a trailing underscore so it does not collide with the parent id.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/suma/schema_discovery.rb', line 40 def build_added_manifest(schema_output_path) doc = CollectionConfig.from_file(manifest.file) doc_id = doc.bibdata.id added = CollectionManifest.new( title: "Collection", type: "collection", identifier: "#{manifest.identifier}_", ) added.entry = [ CollectionManifest.new( title: doc_id, type: "document", entry: build_doc_entries(schema_output_path), ), ] added end |
#build_doc_entries(schema_output_path) ⇒ Object
Build one CollectionManifest per schema in schema_config, naming
each output file as doc_<basename>.xml under
<schema_output_path>/<schema_id>/.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/suma/schema_discovery.rb', line 64 def build_doc_entries(schema_output_path) manifest.schema_config.schemas.map do |schema| xml_basename = "#{File.basename(schema.path, '.exp')}.xml" CollectionManifest.new( identifier: schema.id, title: schema.id, file: File.join(schema_output_path, schema.id, "doc_#{xml_basename}"), ) end end |
#load_config ⇒ Object
If the manifest's file is a collection.yml and a schemas.yaml
sits alongside it, parse it into an Expressir::SchemaManifest and
store it on the manifest. Otherwise leave schema_config untouched.
27 28 29 30 31 32 33 34 35 |
# File 'lib/suma/schema_discovery.rb', line 27 def load_config return unless manifest.file return unless File.basename(manifest.file) == "collection.yml" schemas_yaml_path = File.join(File.dirname(manifest.file), "schemas.yaml") return unless File.exist?(schemas_yaml_path) manifest.schema_config = Expressir::SchemaManifest.from_file(schemas_yaml_path) end |