Skip to content

Commit

Permalink
chore: keep repo serialize public
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Jul 10, 2024
1 parent 380dbff commit 4a2f210
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions lib/esse/repository/object_document_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %<t>p document defined for the %<k>p index', t: repo_name, k: index.to_s)
end

@document_proc.call(model, **kwargs)
end

protected

def coerce_to_document(value)
Expand All @@ -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 %<t>p document defined for the %<k>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
Expand Down
4 changes: 2 additions & 2 deletions spec/esse/repository/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 4a2f210

Please sign in to comment.