Class: Archimate::Diff::Move

Inherits:
Difference show all
Defined in:
lib/archimate/diff/move.rb

Constant Summary

Constants inherited from Difference

Difference::ARRAY_RE, Difference::PATH_ROOT_SORT_ORDER

Instance Attribute Summary

Attributes inherited from Difference

#changed_from, #target

Instance Method Summary collapse

Methods inherited from Difference

#<=>, #==, #change?, #delete?, #insert?, #path_to_array, #summary_element

Constructor Details

#initialize(target, changed_from) ⇒ Move

Create a new Move difference

Parameters:



14
15
16
# File 'lib/archimate/diff/move.rb', line 14

def initialize(target, changed_from)
  super(target, changed_from)
end

Instance Method Details

#apply(to_model) ⇒ Object

TODO: patch is a better name than apply



25
26
27
28
29
30
31
32
33
34
# File 'lib/archimate/diff/move.rb', line 25

def apply(to_model)
  unless to_model.is_a?(DataModel::Model)
    throw(
      TypeError,
      "Expected a Archimate::DataModel::Model, was a #{to_model.class}"
    )
  end
  target.move(to_model, changed_from)
  to_model
end

#kindObject



40
41
42
# File 'lib/archimate/diff/move.rb', line 40

def kind
  "Move"
end

#move?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/archimate/diff/move.rb', line 36

def move?
  true
end

#to_sObject



18
19
20
21
22
# File 'lib/archimate/diff/move.rb', line 18

def to_s
  # Note - the explicit to_s is required to access the DiffableArray
  #        implementation if the parent is an Array.
  "#{diff_type} #{changed_from.parent&.to_s} #{Color.color(target.to_s, :change)} moved to #{target.array_index}"
end