Class: Canopus::Workspace::Edit::Plan

Inherits:
Object
  • Object
show all
Includes:
Executable, ResourcePreparable
Defined in:
lib/canopus/workspace/edit/plan.rb

Overview

Resource edits are uncommon and explicitly confirmed. No filesystem mutation happens until every ordered resource/text operation has passed preflight.

Instance Method Summary collapse

Methods included from Executable

#apply

Constructor Details

#initialize(workspace, edit) ⇒ Plan

Returns a new instance of Plan.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/canopus/workspace/edit/plan.rb', line 17

def initialize(workspace, edit)
  @workspace, @root = workspace, workspace.root
  @nodes, @observed, @originals = {}, {}, {}
  @operations, @new_buffers, @recoveries, @journal = [], [], [], []
  @text_bytes = @edit_count = 0
  changes = edit.fetch("documentChanges")
  raise Error, "invalid documentChanges" unless changes.is_a?(Array) && changes.length <= 10_000
  changes.each_with_index do |change, index|
    @failed_change = index
    raise Error, "invalid workspace change" unless change.is_a?(Hash)
    change["kind"] ? prepare_resource(change, index) : prepare_text(change, index)
  end
  @failed_change = nil
rescue StandardError
  close
  raise
end

Instance Method Details

#close ⇒ Object



35
36
37
# File 'lib/canopus/workspace/edit/plan.rb', line 35

def close
  @new_buffers.each { |buffer| buffer.close unless @workspace.buffers.value?(buffer) }
end