Class: Idml::Composition::Prefix

Inherits:
Object
  • Object
show all
Defined in:
lib/idml/composition/prefix.rb

Overview

Prefix every Self attribute value across every part of a package so it can be safely composed with another package without ID collisions. This is the foundation operation — every other composition op (InsertIdml, AddPageFromIdml) prefixes the source package first.

Returns a new Package; the receiver is unchanged. Round-trips through Package#each_part + Package.write — does not require typed models to be complete.

Instance Method Summary collapse

Constructor Details

#initialize(package) ⇒ Prefix

Returns a new instance of Prefix.



15
16
17
# File 'lib/idml/composition/prefix.rb', line 15

def initialize(package)
  @package = package
end

Instance Method Details

#call(prefix:) ⇒ Object



19
20
21
22
23
24
# File 'lib/idml/composition/prefix.rb', line 19

def call(prefix:)
  parts = @package.each_part.to_a.to_h do |name, xml|
    [name, prefix_references(name, xml, prefix)]
  end
  Package.write(parts: parts, to: tmp_path)
end