Class: Opencdd::Parcel::EntityManifest
- Inherits:
-
Object
- Object
- Opencdd::Parcel::EntityManifest
- Defined in:
- lib/opencdd/parcel/entity_manifest.rb
Overview
Reads the harvester's _entity.json sidecar format
and converts it into Opencdd::Entity::VersionHistory entries
and stub entities for cross-reference resolution.
Extracted from ShardedDirReader so the JSON-shape concern has its own home and can be tested with a hash fixture instead of requiring a full directory tree on disk.
The sidecar schema (produced by harvest/download_versions.py):
{
"irdi": "0112/2///62656_1#AAA001",
"entity_type": "class", # Symbol
"current_version_dir": "ABC123...", # UNID subfolder name
"versions": [
{ "version": 1, "revision": 0, "status": "Released",
"timestamp": "2024-01-15T10:23:00Z", "user": "...",
"change_request_id": "...", "unid": "...",
"is_current": true }
]
}
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.read(entity_dir) ⇒ Object
Returns a manifest for
entity_dir, ornilwhen no_entity.jsonlives there or the file is unparseable.
Instance Method Summary collapse
-
#current_version_dir ⇒ Object
Name of the per-version subfolder that holds the current version's XLS exports.
-
#entity_type ⇒ Object
Symbol type (:class, :property, ...) or
nil. -
#initialize(data, path = nil) ⇒ EntityManifest
constructor
A new instance of EntityManifest.
-
#irdi ⇒ Object
IRDI of the entity this manifest describes, or
nil. -
#meta_class_code ⇒ Object
Meta-class IRDI code (e.g. "MDC_C002"), or
nilif the type isn't registered. -
#to_stub_entity ⇒ Object
Constructs a minimal stub entity from this manifest, so cross-references to entities that weren't loaded from a
.xlsstill resolve. -
#version_history ⇒ Object
Version history compiled from the
versionsarray. - #versions_empty? ⇒ Boolean
Constructor Details
#initialize(data, path = nil) ⇒ EntityManifest
Returns a new instance of EntityManifest.
42 43 44 45 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 42 def initialize(data, path = nil) @data = data @path = path end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
29 30 31 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 29 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
29 30 31 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 29 def path @path end |
Class Method Details
.read(entity_dir) ⇒ Object
Returns a manifest for entity_dir, or nil when no
_entity.json lives there or the file is unparseable.
33 34 35 36 37 38 39 40 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 33 def self.read(entity_dir) path = File.join(entity_dir, "_entity.json") return nil unless File.file?(path) data = JSON.parse(File.read(path)) new(data, path) rescue JSON::ParserError nil end |
Instance Method Details
#current_version_dir ⇒ Object
Name of the per-version subfolder that holds the current
version's XLS exports. nil for flat-layout manifests.
67 68 69 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 67 def current_version_dir @data["current_version_dir"] end |
#entity_type ⇒ Object
Symbol type (:class, :property, ...) or nil.
55 56 57 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 55 def entity_type @data["entity_type"]&.to_sym end |
#irdi ⇒ Object
IRDI of the entity this manifest describes, or nil.
48 49 50 51 52 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 48 def irdi raw = @data["irdi"] return nil if raw.nil? Opencdd::IRDI.parse(raw.to_s) end |
#meta_class_code ⇒ Object
Meta-class IRDI code (e.g. "MDC_C002"), or nil if the
type isn't registered.
61 62 63 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 61 def Opencdd::MetaClasses.(entity_type) end |
#to_stub_entity ⇒ Object
Constructs a minimal stub entity from this manifest, so
cross-references to entities that weren't loaded from a
.xls still resolve. Returns nil if the manifest lacks
an IRDI, type, or known meta-class.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 89 def to_stub_entity return nil unless irdi && = Opencdd::MetaClasses.for() return nil unless &.entity_class code_property_id = Opencdd::MetaClasses.code_property_id_for() props = code_property_id ? { code_property_id => @data["irdi"].to_s } : {} .entity_class.new( irdi: irdi, properties: props, meta_class_irdi: Opencdd::IRDI.parse(), ) end |
#version_history ⇒ Object
Version history compiled from the versions array.
Empty when no versions are listed.
73 74 75 76 77 78 79 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 73 def version_history vh = Opencdd::Entity::VersionHistory.new Array(@data["versions"]).each do |v| vh.attach(build_entry(v)) end vh end |
#versions_empty? ⇒ Boolean
81 82 83 |
# File 'lib/opencdd/parcel/entity_manifest.rb', line 81 def versions_empty? Array(@data["versions"]).empty? end |