Class: Archimate::Diff::ArchimateNodeAttributeReference

Inherits:
ArchimateNodeReference show all
Defined in:
lib/archimate/diff/archimate_node_attribute_reference.rb

Instance Attribute Summary collapse

Attributes inherited from ArchimateNodeReference

#archimate_node

Instance Method Summary collapse

Methods inherited from ArchimateNodeReference

for_node, #lookup_parent_in_model, #parent, #recurse_lookup_in_model

Constructor Details

#initialize(archimate_node, attribute) ⇒ ArchimateNodeAttributeReference

Returns a new instance of ArchimateNodeAttributeReference.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 8

def initialize(archimate_node, attribute)
  unless archimate_node.is_a?(DataModel::ArchimateNode)
    raise(
      TypeError,
      "archimate_node must be an ArchimateNode, was #{archimate_node.class}"
    )
  end
  unless attribute.is_a?(Symbol)
    raise(
      TypeError,
      "Node #{archimate_node.class} attribute must be a sym, was a #{attribute.class} value #{attribute.inspect}"
    )
  end
  unless archimate_node.class.schema.keys.include?(attribute)
    raise(
      ArgumentError,
      "Attribute #{attribute} invalid for class #{archimate_node.class}"
    )
  end
  super(archimate_node)
  @attribute = attribute
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 6

def attribute
  @attribute
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 31

def ==(other)
  super && attribute == other.attribute
end

#change(to_model, _from_value) ⇒ Object



61
62
63
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 61

def change(to_model, _from_value)
  lookup_parent_in_model(to_model).set(attribute, value)
end

#delete(to_model) ⇒ Object



57
58
59
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 57

def delete(to_model)
  lookup_parent_in_model(to_model).delete(attribute)
end

#insert(to_model) ⇒ Object



53
54
55
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 53

def insert(to_model)
  lookup_parent_in_model(to_model).set(attribute, value)
end

#lookup_in_model(model) ⇒ Object



35
36
37
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 35

def lookup_in_model(model)
  recurse_lookup_in_model(archimate_node, model)[attribute]
end

#move(_to_model) ⇒ Object



65
66
67
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 65

def move(_to_model)
  raise "Move is not valid for ArchimateNodes"
end

#path(options = {}) ⇒ Object



47
48
49
50
51
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 47

def path(options = {})
  @node_attribute_ref_path ||= [
    super, @attribute
  ].map(&:to_s).reject(&:empty?).join("/")
end

#to_sObject



39
40
41
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 39

def to_s
  attribute.to_s
end

#valueObject



43
44
45
# File 'lib/archimate/diff/archimate_node_attribute_reference.rb', line 43

def value
  archimate_node[attribute]
end