Class: Collab::Models::TrackedPosition
- Defined in:
- lib/collab/models/tracked_position.rb
Overview
Represents a position in the document which is tracked between commits
If the position is deleted through mapping, deleted_at_version will be set, the position will no longer be tracked,
Class Method Summary collapse
-
.resolve(document, *positions, version:) ⇒ Object
Resolves a set of positions and yields them to the block given, returning the result of the block The document will be locked IN SHARE MODE during resolution and the block execution Positions should consist of => number, “assoc”: number Returns false if invalid version or any position has been deleted.
Class Method Details
.resolve(document, *positions, version:) ⇒ Object
Resolves a set of positions and yields them to the block given, returning the result of the block The document will be locked IN SHARE MODE during resolution and the block execution Positions should consist of => number, “assoc”: number Returns false if invalid version or any position has been deleted
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/collab/models/tracked_position.rb', line 22 def self.resolve(document, *positions, version:) raise false unless document.possibly_saved_version? version document.with_lock("FOR SHARE") do unless document.document_version == version steps = document.commits.where("document_version > ?", @mapped_to).order(document_version: :asc).pluck(:steps).flatten(1) map_results = ::Collab::JS.map_through(steps: steps, pos: positions)["pos"] map_results.each_with_index do |r, i| return false if r["deleted"] positions[i]["pos"] = r["pos"] end end positions.map! do |p| document.tracked_positions.current.find_or_initialize_by(pos: p["pos"], assoc: p["assoc"]) end yield(*positions) end end |