Class: Mxrb::Semantic::MovePlan

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MovePlan.



8
9
10
11
12
13
14
15
# File 'lib/mxrb/semantic/mover.rb', line 8

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

Instance Attribute Details

#before_containerObject (readonly)

Returns the value of attribute before_container.



6
7
8
# File 'lib/mxrb/semantic/mover.rb', line 6

def before_container
  @before_container
end

#containment_nameObject (readonly)

Returns the value of attribute containment_name.



6
7
8
# File 'lib/mxrb/semantic/mover.rb', line 6

def containment_name
  @containment_name
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/mxrb/semantic/mover.rb', line 6

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



6
7
8
# File 'lib/mxrb/semantic/mover.rb', line 6

def target
  @target
end

Instance Method Details

#after_containerObject



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

def after_container = target.unit_id

#applied?Boolean

Returns:

  • (Boolean)


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

def applied? = @applied

#apply!Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mxrb/semantic/mover.rb', line 21

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

  unless empty?
    @project.mpr.transaction do
      @project.mpr.relocate_unit(
        source.unit_id,
        container_uuid: after_container,
        containment_name:
      )
    end
  end
  @project.refresh!
  @applied = true
  self
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty? = before_container == after_container