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, Shale::Type::String



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

def schema_config
  @schema_config
end

Instance Method Details

#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

#expand_schemas_only(schema_output_path) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/suma/collection_manifest.rb', line 67

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

  # 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

  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

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

  entries = @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

  # 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,
    ),
  ]

  [self, added]
end

#export_schema_config(path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/suma/collection_manifest.rb', line 37

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



49
50
51
52
53
# File 'lib/suma/collection_manifest.rb', line 49

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



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/suma/collection_manifest.rb', line 55

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



117
118
119
120
121
122
# File 'lib/suma/collection_manifest.rb', line 117

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