Class: Mxrb::Semantic::Mover

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

Constant Summary collapse

EMBEDDED_KINDS =
%i[module entity attribute association].freeze
CONTAINER_KINDS =
%i[module folder].freeze

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Mover

Returns a new instance of Mover.



82
83
84
# File 'lib/mxrb/semantic/mover.rb', line 82

def initialize(project)
  @project = project
end

Instance Method Details

#plan(name, to:) ⇒ Object

Raises:

  • (ArgumentError)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mxrb/semantic/mover.rb', line 86

def plan(name, to:)
  source = resolve(name)
  target = resolve(to)
  validate_kinds(source, target)

  raw = @project.raw_unit(source.unit_id)
  raise ArgumentError, "#{source.qualified_name} is not a movable unit" unless raw
  if descendant_ids(source.unit_id).include?(target.unit_id)
    raise ArgumentError, "cannot move #{source.qualified_name} into its descendant"
  end

  if source.module_name != target.module_name
    plan_cross_module(source, target, raw)
  else
    MovePlan.new(
      project: @project,
      source:,
      target:,
      before_container: raw.fetch("ContainerID"),
      containment_name: raw.fetch("ContainmentName")
    )
  end
end