lib/hexapdf/document.rb in hexapdf-0.27.0 vs lib/hexapdf/document.rb in hexapdf-0.28.0

- old
+ new

@@ -162,20 +162,19 @@ # HexaPDF::DefaultDocumentConfiguration[../index.html#DefaultDocumentConfiguration], # meaning that direct sub-hashes are merged instead of overwritten. def initialize(io: nil, decryption_opts: {}, config: {}) @config = Configuration.with_defaults(config) @version = '1.2' + @cache = Hash.new {|h, k| h[k] = {} } + @listeners = {} @revisions = Revisions.from_io(self, io) @security_handler = if encrypted? && @config['document.auto_decrypt'] Encryption::SecurityHandler.set_up_decryption(self, **decryption_opts) else nil end - - @listeners = {} - @cache = Hash.new {|h, k| h[k] = {} } end # :call-seq: # doc.object(ref) -> obj or nil # doc.object(oid) -> obj or nil @@ -249,22 +248,19 @@ end # :call-seq: # doc.import(obj) -> imported_object # - # Imports the given, with a different document associated PDF object and returns the imported + # Imports the given object from a different HexaPDF::Document instance and returns the imported # object. # # If the same argument is provided in multiple invocations, the import is done only once and - # the previously imoprted object is returned. + # the previously imported object is returned. # # See: Importer def import(obj) - if !obj.kind_of?(HexaPDF::Object) || !obj.document? || obj.document == self - raise ArgumentError, "Importing only works for PDF objects associated " \ - "with another document" - end - HexaPDF::Importer.for(source: obj.document, destination: self).import(obj) + source = (obj.kind_of?(HexaPDF::Object) ? obj.document : nil) + HexaPDF::Importer.for(self).import(obj, source: source) end # Wraps the given object inside a HexaPDF::Object class which allows one to use # convenience functions to work with the object. #