Class: Archimate::Diff::Insert

Inherits:
Difference show all
Defined in:
lib/archimate/diff/insert.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?, #move?, #path_to_array, #summary_element

Constructor Details

#initialize(target) ⇒ Insert

Create a new Insert difference

Parameters:

  • inserted_element (Archimate::DataModel::ArchimateNode)

    Element that was inserted

  • sub_path (str)

    Path under inserted_element for primitive values



12
13
14
# File 'lib/archimate/diff/insert.rb', line 12

def initialize(target)
  super
end

Instance Method Details

#apply(to_model) ⇒ Object



22
23
24
25
26
# File 'lib/archimate/diff/insert.rb', line 22

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

#insert?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/archimate/diff/insert.rb', line 28

def insert?
  true
end

#kindObject



32
33
34
# File 'lib/archimate/diff/insert.rb', line 32

def kind
  "Insert"
end

#to_sObject



16
17
18
19
20
# File 'lib/archimate/diff/insert.rb', line 16

def to_s
  # Note - the explicit to_s is required to access the DiffableArray
  #        implementation if the parent is an Array.
  "#{diff_type} #{target} into #{target.parent.to_s}"
end