From e1f3f26cfbb089dab0574f22e7876158d02829b6 Mon Sep 17 00:00:00 2001 From: "Marcos G. Zimmermann" Date: Wed, 10 Jul 2024 12:01:19 -0300 Subject: [PATCH] chore: keep repo serialize public --- lib/esse/repository/object_document_mapper.rb | 24 +++++++++---------- spec/esse/repository/document_spec.rb | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/esse/repository/object_document_mapper.rb b/lib/esse/repository/object_document_mapper.rb index 4efe16d..989e92c 100644 --- a/lib/esse/repository/object_document_mapper.rb +++ b/lib/esse/repository/object_document_mapper.rb @@ -97,6 +97,18 @@ def documents(**kwargs) end end + # Convert ruby object to json by using the document of the given document type. + # @param [Object] model The ruby object + # @param [Hash] kwargs The context + # @return [Esse::Document] The serialized document + def serialize(model, **kwargs) + if @document_proc.nil? + raise NotImplementedError, format('there is no %p document defined for the %p index', t: repo_name, k: index.to_s) + end + + @document_proc.call(model, **kwargs) + end + protected def coerce_to_document(value) @@ -112,18 +124,6 @@ def coerce_to_document(value) end end - # Convert ruby object to json by using the document of the given document type. - # @param [Object] model The ruby object - # @param [Hash] kwargs The context - # @return [Esse::Document] The serialized document - def serialize(model, **kwargs) - if @document_proc.nil? - raise NotImplementedError, format('there is no %p document defined for the %p index', t: repo_name, k: index.to_s) - end - - @document_proc.call(model, **kwargs) - end - # Used to fetch all batch of data defined on the collection model. # Arguments can be anything. They will just be passed through the block. # Useful when the collection depends on scope or any other conditions diff --git a/spec/esse/repository/document_spec.rb b/spec/esse/repository/document_spec.rb index e3a983a..d7f834b 100644 --- a/spec/esse/repository/document_spec.rb +++ b/spec/esse/repository/document_spec.rb @@ -10,7 +10,7 @@ specify do expect { - DummiesIndex::Dummy.send(:serialize, double) + DummiesIndex::Dummy.serialize(double) }.to raise_error( NotImplementedError, 'there is no "dummy" document defined for the "DummiesIndex" index', @@ -35,7 +35,7 @@ end specify do - expect(DummiesIndex::Dummy.send(:serialize, dummy, **optionals)).to eq( + expect(DummiesIndex::Dummy.serialize(dummy, **optionals)).to eq( Esse::HashDocument.new( _id: 1, name: 'dummy',