Class: Mxrb::Semantic::CrossModuleMovePlan

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/semantic/mover.rb

Overview

Cross-module move: relocates a unit AND renames its qualified name across the project so that all references stay consistent.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, source:, target:, rename_plan:, before_container:, containment_name:) ⇒ CrossModuleMovePlan

Returns a new instance of CrossModuleMovePlan.



44
45
46
47
48
49
50
51
52
# File 'lib/mxrb/semantic/mover.rb', line 44

def initialize(project:, source:, target:, rename_plan:, before_container:, containment_name:)
  @project = project
  @source = source
  @target = target
  @rename_plan = rename_plan
  @before_container = before_container
  @containment_name = containment_name
  @applied = false
end

Instance Attribute Details

#before_containerObject (readonly)

Returns the value of attribute before_container.



42
43
44
# File 'lib/mxrb/semantic/mover.rb', line 42

def before_container
  @before_container
end

#rename_changesObject (readonly)

Returns the value of attribute rename_changes.



42
43
44
# File 'lib/mxrb/semantic/mover.rb', line 42

def rename_changes
  @rename_changes
end

#sourceObject (readonly)

Returns the value of attribute source.



42
43
44
# File 'lib/mxrb/semantic/mover.rb', line 42

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



42
43
44
# File 'lib/mxrb/semantic/mover.rb', line 42

def target
  @target
end

Instance Method Details

#after_containerObject



54
# File 'lib/mxrb/semantic/mover.rb', line 54

def after_container = target.unit_id

#applied?Boolean

Returns:

  • (Boolean)


57
# File 'lib/mxrb/semantic/mover.rb', line 57

def applied? = @applied

#apply!Object

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mxrb/semantic/mover.rb', line 59

def apply!
  raise ArgumentError, "cross-module move plan was already applied" if applied?

  @project.mpr.transaction do
    @rename_plan.documents.each do |unit_id, doc|
      @project.mpr.update_unit(unit_id, doc)
    end
    @project.mpr.relocate_unit(
      @source.unit_id,
      container_uuid: @target.unit_id,
      containment_name: @containment_name
    )
  end
  @project.refresh!
  @applied = true
  self
end

#empty?Boolean

Returns:

  • (Boolean)


55
# File 'lib/mxrb/semantic/mover.rb', line 55

def empty? = false